【发布时间】:2013-12-20 13:29:37
【问题描述】:
我是 php 中的上传功能的新手,但是我有这个:
if( $_FILES[$fileElementName]['type'] !== "image/gif"
|| $_FILES[$fileElementName]['type'] !== "image/jpeg"
|| $_FILES[$fileElementName]['type'] !== "image/jpg"
|| $_FILES[$fileElementName]['type'] !== "image/pjpeg"
|| $_FILES[$fileElementName]['type'] !== "image/x-png"
|| $_FILES[$fileElementName]['type'] !== "image/png"
|| $_FILES[$fileElementName]['type'] == "application/x-rar-compressed"
){
$error = 'wrong file only :GIF,jpg,png .';
// die($_FILES[$fileElementName]['type']); // also i did die here to check
}
但它不会工作,即使我上传 jpg,它也会说总是错误的。 我确实死了/var_damp,并且该类型适用于 E.G,一切正常: 我上传了 sds.jpg 并让其给出正确:
image/jpeg
但它会一直说总是错误的文件,为什么?
【问题讨论】:
-
将您的
||换成&&。发生的情况是,如果(它不是 gif)或(它不是 jpg)您的陈述是正确的 - 因为您上传的是 jpg,所以 gif 永远是正确的。 -
更简洁的方法是
if (!in_array($_FILES[$fileElementName]['type'], array('image/jpeg','image/jpg','image/png',.....))) {// bad type...}
标签: php