开发者

Validator Zend_Validate_File_IsImage doesn't work correct

I try to use the next validator of ZF:

$isImageValidator = new Zend_Validate_File_IsImage(array('headerCheck' => true));

(I don'n wa开发者_如何转开发nt to use fileInfo or mimeMagic)

But even when image is chosen, validator returns next:

File 'image.png' is no image, 'application/octet-stream' detected

(When i look through the $_FILES global array it detects 'image/png') Why???

Help me please...


I have same issue at my prod server. By default Zend_Validate_File_MimeType which is base class of isImage uses one of files wich define mime types in your system.

In my case this file was /usr/share/file/magic.mime

I just removed all that files which was listed in 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',
);


Try:

$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;
}));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜