Zend_Validate_File_IsImage validator is not working correctly

I am trying to use the following ZF validator:

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

(I do not want to use fileInfo or mimeMagic)

But even when the image is selected, the validator returns the following:

File 'image.png' does not contain an image, application / octet stream detected

(When I scan the global $ _FILES array, it detects "image / png"). Why???

Help me please...

+3
source share
2 answers

prod-. Zend_Validate_File_MimeType, isImage, , 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',
);
0

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

Source: https://habr.com/ru/post/1759208/


All Articles