瀏覽代碼

block invalid type file

master
Anna Ho 1 年之前
父節點
當前提交
516e28e7ad
共有 1 個文件被更改,包括 14 次插入4 次删除
  1. +14
    -4
      src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js

+ 14
- 4
src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js 查看文件

@@ -92,9 +92,19 @@ const PublicNoticeApplyForm = ({loadedData, selections}) => {
});

const readFile=(event)=>{
if(event.target.files[0]){
if(event.target.files[0])
setAttachment(event.target.files[0]);
let file = event.target.files[0];
if(file){
if(file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.documen"
|| file.type == "application/msword"
|| file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|| file.type == "application/vnd.ms-excel"
){
setAttachment(event.target.files[0]);
}else{
setWarningText("請上傳有效檔案 (檔案格式: .doc, .docx, .xls, .xlsx)");
setIsWarningPopUp(true);
return;
}
}
}

@@ -178,7 +188,7 @@ const PublicNoticeApplyForm = ({loadedData, selections}) => {
id="uploadFileBtn"
name="file"
type="file"
accept=".doc,.docx,.xml,.xlsx"
accept=".doc,.docx,.xls,.xlsx"
style={{ display: 'none' }}
onChange={(event)=> {
readFile(event)


Loading…
取消
儲存