使用javascript进行文件上传验证

时间:2015-04-20 13:05:39

标签: javascript

我的表格如下:

<span> Upload CV :</span><input type="file" id="flu"  name="filename" /> 

我正在调用验证函数如下

<form name="frm" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit = "return validateForm()" enctype="multipart/form-data">

验证功能如下

else if (document.forms["frm"].filename.value == null ||  document.forms["frm"].filename.value== "") {
             document.getElementById("fullnameerr").innerHTML="";
             document.getElementById("subspecerr").innerHTML="";
             document.getElementById("emailerr").innerHTML="";
             document.getElementById("mobileerr").innerHTML="";
             document.getElementById("pperr").innerHTML="";
             document.getElementById("dateerr").innerHTML="";
             document.getElementById("currentworkerr").innerHTML="";
             document.getElementById("filenameerr").innerHTML="Please upload your CV";
             document.forms["frm"].filename.focus();
        return false;
        }

  else if (document.forms["frm"].captcha.value == null ||  document.forms["frm"].captcha.value== "") {
             document.getElementById("fullnameerr").innerHTML="";
             document.getElementById("subspecerr").innerHTML="";
             document.getElementById("emailerr").innerHTML="";
             document.getElementById("mobileerr").innerHTML="";
             document.getElementById("pperr").innerHTML="";
             document.getElementById("dateerr").innerHTML="";
             document.getElementById("currentworkerr").innerHTML="";
             document.getElementById("filenameerr").innerHTML="";
             document.getElementById("captchatxterr").innerHTML="Please enter image text";
             document.forms["frm"].captcha.focus();
           return false;
        }
  else  {
        return true;
        }                 

如何验证文件上传以检查1 MB的文件大小,它应该提交.doc和.pdf文档,任何帮助都可能非常感谢。

0 个答案:

没有答案