AW: [fw-general] Zend_Validate_File_IsImage return "File 'image.png' is no image, 'application/octet-stream' detected".

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AW: [fw-general] Zend_Validate_File_IsImage return "File 'image.png' is no image, 'application/octet-stream' detected".

Thomas Weidner
Hy,

the IsImage validator uses the mimetype detected from the file itself, not
the one which is send from the customer.
Otherwise someone could send you an file and say it's an image but instead
it's an exe file.

Thomas Weidner

Zend Framework Certified Engineer & I18N Team Leader
http://www.thomasweidner.com

-----Urspr√ľngliche Nachricht-----
Von: vbogoev [mailto:[hidden email]]
Gesendet: Mittwoch, 11. Mai 2011 14:20
An: [hidden email]
Betreff: [fw-general] Zend_Validate_File_IsImage return "File 'image.png' is
no image, 'application/octet-stream' detected".

I try to use the Zend_Validate_File_IsImage, but 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')

Anybody knows what's the solution of this problem? Adding some additional
extensions or something...

I am using PHP 5.3.6.

Also using imagick and fileinfo extension.

I realized that in php 5.3.0 and above there are no MIME_MAGICK extension.
Functions are implemented in fileinfo. When I used php 5.2.8 this extension
resolved this problem, but now...

Linux hosting.

If you need any other question feel free to ask me!

Thanks!

--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-Validate-File-IsIm
age-return-File-image-png-is-no-image-application-octet-stream-detected-tp35
14523p3514523.html
Sent from the Zend Framework mailing list archive at Nabble.com.

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]




--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: AW: [fw-general] Zend_Validate_File_IsImage return "File 'image.png' is no image, 'application/octet-stream' detected".

Michael Pedrotti
This post has NOT been accepted by the mailing list yet.
This post was updated on .
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("File is no image, %s detected", $file['type']));
      return false;
   }
   return true;
}));


$filepath = temporary file name;
$file = (
    [name] => File.jpg
    [type] => image/jpeg
    [tmp_name] => /tmp/phpREiy2E
    [error] => 0
    [size] => 167153
    [options] => Array
        (
            [ignoreNoFile] =>
            [useByteString] => 1
            [magicFile] =>
            [detectInfos] => 1
        )

    [validated] =>
    [received] =>
    [filtered] =>
    [validators] => Array
        (
            [0] => Zend_Validate_File_Upload
            [1] => Zend_Validate_File_Count
            [2] => Zend_Validate_Callback
        )

    [destination] => /opt/lampp/htdocs/project1/temp
);