无论如何要通过<input type="file" />元素限制文件类型的选择?
例如,如果我只想上传图像类型,我会将可能的选择限制为(image/jpg,image/gif,image/png),选择对话框会使其他mime类型的文件变灰.
ps我知道我可以通过扫描.type属性在File API之后执行此操作.我真的试图限制这一点..我也知道我可以通过闪存做到这一点,但我不想为此使用闪存.
我有以下代码来检查(上传的简历和推荐信是否符合所需类型(pdf或doc或docx)和大小(小于400 kb)
//check file extension and size
$resume= ($_FILES['resume']['name']);
$reference= ($_FILES['reference']['name']);
$ext = strrchr($resume, ".");
$ext1 = strrchr($reference, ".");
if (!(($_FILES["resume"]["type"] == "application/doc")
|| ($_FILES["resume"]["type"] == "application/docx")
|| ($_FILES["resume"]["type"] == "application/pdf" ))
&& (($_FILES["reference"]["type"] == "application/doc")
|| ($_FILES["reference"]["type"] == "application/docx")
|| ($_FILES["reference"]["type"] == "application/pdf"))
&& (($ext == ".pdf") || ($ext == ".doc") || ($ext == ".docx"))
&& (($ext1 == ".pdf") || ($ext1 == ".doc") || ($ext1 == ".docx"))
&& ($_FILES["resume"]["size"] < 400000) //accept upto 500 kb
&& ($_FILES["reference"]["size"] < 400000)) …Run Code Online (Sandbox Code Playgroud)