我在上传前检查文件时遇到一些问题。
我目前检查的代码如下:
public function verify_file(){
$allowedExts = array("jpeg", "jpg", "png", "bmp");
$temp = explode(".", $_FILES["page-add-file-box"]["name"]);
$extension = end($temp);
if ((($_FILES["page-add-file-box"]["type"] == "image/jpeg")
|| ($_FILES["page-add-file-box"]["type"] == "image/jpg")
|| ($_FILES["page-add-file-box"]["type"] == "image/pjpeg")
|| ($_FILES["page-add-file-box"]["type"] == "image/x-png")
|| ($_FILES["page-add-file-box"]["type"] == "image/png"))
&& ($_FILES["page-add-file-box"]["size"] <= 100000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["page-add-file-box"]["error"] > 0)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
为什么上面的代码有效,下面的代码没有?
if(($_FILES["page-add-file-box"]["type"] != "image/jpeg")
&& ($_FILES["page-add-file-box"]["type"] != "image/jpg")
&& ($_FILES["page-add-file-box"]["type"] != "image/pjpeg")
&& ($_FILES["page-add-file-box"]["type"] != "image/x-png")
&& ($_FILES["page-add-file-box"]["type"] != "image/png")
&& (!in_array($extension, $allowedExts))){
return false;
}else{
if($_FILES["page-add-file-box"]["size"] <= 100000){
return false;
}
if($_FILES["page-add-file-box"]["error"] > 0){
return false;
}
}
return true;
我已经过测试,我知道在return false
!in_array()
失败了