2

While uploading file I am getting mime-type as application/octet-stream.

I have come to know that Zend_Frameworks tries to determine the mimetype in two ways:

First it tries to use the PECL FILEINFO-Extension (which is not installed on every server) if the extension is not istalled it tries to use mime_content_type (a php function). This function however is deprecated as of php version 5.3

So what to do now? How can I be sure that user uploading a file is image only and not something else? How can I detect mime type of uploaded file?

Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62

2 Answers2

1

For images you can also rely on exif_imagetype but I would recommend that you install finfo.

See this for an example implementation.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
0

Use Zend_File_Transfer validators to exlude types that you dont want :

    $upload = new Zend_File_Transfer();

   // Does not allow MIME type application/pdf and application/zip .
   $upload->addValidator('ExcludeMimeType', false, array('application/pdf',
                                                  'application/zip'));

or you can also use IsImage validator which checks if a transferred file is a image file :

$upload = new Zend_File_Transfer();

// Checks whether the uploaded file is a image file
$upload->addValidator('IsImage', false);
Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69