我想添加更多文件类型扩展名,如 zip、rar 和 pdf,但我无法这样做,因为“getimagesize”只允许图像文件类型。
define('TYPE_WHITELIST', serialize(array(
'image/jpeg',
'image/png',
'image/gif',
'application/zip',
'application/rar',
'application/pdf'
)));
for($i=0; $i<count($_FILES['agp_gallery']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['agp_gallery']['tmp_name'][$i];
if ($tmpFilePath == "") {
}
else {
$image_data = getimagesize($tmpFilePath);
if(!in_array($image_data['mime'], unserialize(TYPE_WHITELIST))){
$result['error'] = 'Your image must be a jpeg, png or gif!';
}
}
}