2010-08-11 95 views
3

我嘗試使用ZF的下一個驗證:驗證Zend_Validate_File_IsImage不起作用正確

$ isImageValidator =新Zend_Validate_File_IsImage(陣列( 'headerCheck'=>真));

(我don'n要使用的fileInfo或mimeMagic)

但是選擇圖像,即使,驗證返回未來:

文件 'image.png' 沒有圖像,「應用/ octet-流'檢測

(當我通過$ _FILES全局數組它檢測'圖像/ PNG')爲什麼?

請幫助我...

回答

0

我在我的prod服務器上有同樣的問題。默認情況下,Zend_Validate_File_MimeType是isImage的基類,它使用一個文件來定義系統中的MIME類型。

在我的情況下,該文件是/usr/share/file/magic.mime

我只是刪除了所有的這是在Mime類型列出的文件:

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

嘗試:

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