我尝试使用ZF的下一个验证器:
$ isImageValidator = new Zend_Validate_File_IsImage(array('headerCheck'=> true));
(我不想使用fileInfo或mimeMagic)
但即使选择了图像,验证器也会返回:
文件'image.png'没有图像,检测到'application / octet-stream'
(当我查看$ _FILES全局数组时,它检测到'image / png')为什么???
请帮帮我......
答案 0 :(得分:0)
我的prod服务器上有同样的问题。默认情况下,作为isImage基类的Zend_Validate_File_MimeType使用一个在系统中定义mime类型的文件。
在我的情况下,这个文件是/usr/share/file/magic.mime
我刚刚删除了MimeType中列出的所有文件:
protected $_magicFiles = array(
'/usr/share/misc/magic',
'/usr/share/misc/magic.mime',
'/usr/share/misc/magic.mgc',
'/usr/share/mime/magic',
'/usr/share/mime/magic.mime',
'/usr/share/mime/magic.mgc',
'/usr/share/file/magic',
'/usr/share/file/magic.mime',
'/usr/share/file/magic.mgc',
);
答案 1 :(得分:0)
尝试:
$transfer = new Zend_File_Transfer_Adapter_Http();
// $transfer->addValidator(new Zend_Validate_File_IsImage());
$transfer->addValidator(new Zend_Validate_Callback(function($filepath, $file) use($transfer){
$mimes = array('image/bmp', 'image/c', 'image/cgm', 'image/fif', 'image/gif', 'image/jpeg', 'image/jpm', 'image/jpx', 'image/jp2', 'image/naplps', 'image/pjpeg', 'image/png', 'image/svg', 'image/svg+xml', 'image/tiff', 'image/vnd.adobe.photoshop', 'image/vnd.djvu', 'image/vnd.fpx', 'image/vnd.net-fpx', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-coreldraw', 'image/x-cpi', 'image/x-emf', 'image/x-ico', 'image/x-icon', 'image/x-jg', 'image/x-ms-bmp', 'image/x-niff', 'image/x-pict', 'image/x-pcx', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap', 'image/x-quicktime', 'image/x-rgb', 'image/x-tiff', 'image/x-unknown', 'image/x-windows-bmp', 'image/x-xpmi');
if(!in_array($file['type'], $mimes)) {
$transfer->addError(sprintf("O arquivo não é uma imagem: '%s' detectado", $file['type']));
return false;
}
return true;
}));