Php can';t检查正在上载的文件的类型
我有这个函数来检查文件是否是图像,但它总是返回falsePhp can';t检查正在上载的文件的类型,php,file-upload,file-extension,Php,File Upload,File Extension,我有这个函数来检查文件是否是图像,但它总是返回false function upload_file($file) { if($file['type'] != "image/jpeg" || $file['type'] != "image/gif") { $errors[] = "Please upload a photograph with extenstion of JPEG, JPG, GIF or BMP.";
function upload_file($file) {
if($file['type'] != "image/jpeg" || $file['type'] != "image/gif") {
$errors[] = "Please upload a photograph with extenstion of JPEG, JPG, GIF or BMP.";
return false;
}
}
谁能告诉我哪里出了问题
提前谢谢
if($file['type'] != "image/jpeg" || $file['type'] != "image/gif") {
应该是
if($file['type'] !== "image/jpeg" || $file['type'] !== "image/gif") {
编辑:没关系,这无关紧要您需要使用
&&
:
if($file['type'] != "image/jpeg" && $file['type'] != "image/gif") {
通过使用
| |
您会导致它总是错误的,因为没有图像可以同时是jpeg和gif,实际上,这只是广告与检查的类型比较,这在这里不是问题