我正在上传 tif 文件,但总是收到回显“不支持上传的文件类型”。为什么? 如何根据我支持的文件数组检查文件是否受支持
//image types supported
$types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_TIFF);
list($width, $height, $type) = getimagesize($_FILES[$name]['tmp_name']);
$ext = image_type_to_extension($type); // get the extension
if (!isset($types[$type])) {
echo = 'The uploaded file type is not supported';
} else
echo = 'All good!';
}
最佳答案
您正在检查 $types
是否具有键 $type
而不是值 $type
。而是使用 in_array。
另请填写 http://www.php.net/manual/en/function.image-type-to-mime-type.php ,没有 IMAGETYPE_TIFF
而是 IMAGETYPE_TIFF_II
和 IMAGETYPE_TIFF_MM
$types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
...
if (in_arry($type,$types)) {
关于php - 如何检查上传的文件是否是受支持的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17394017/