您好,我在使用php in_array函数时遇到问题。 我想检查上传的文件扩展名是否符合我的要求,为此,我正在使用以下代码。
$imgExtension = explode(".",$imageName);
$allowed_extension = array("png","jpg","jpeg","gif");
echo $end = end($imgExtension);
if(in_array(trim($end),$allowed_extension)){
echo "File is correct";
}else{
echo "File is incorrect";
}
我面临的问题是in_array函数,上传文件的扩展名是jpg,png和jpeg,但是in_array条件变为false,不知道为什么...
但不是$ end变量,如果我在in_array函数参数中传递诸如“ jpg”或“ png”之类的任何字符串,那么它将起作用...