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?
For images you can also rely on exif_imagetype
but I would recommend that you install finfo
.
See this for an example implementation.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.