Can't detect MIME type when using Zend Zend_File_Transfer_Adapter_Http !
I am writing a small script to upload and detect MIME type, using Zend Framework. For the design purpose, I can't use Zend_Form but normal instead. And I simply apply from the manual :
$adapter = new Zend_File_Transfer_Adapter_Http(); $files = $adapter->getFileInfo(); $mime = $files->getMimeType();
But the system inform that the funcion getMimeType() does not existed. Then, I tried:
$adapter = new Zend开发者_如何转开发_File_Transfer(); $files = $adapter->getFileInfo(); $mime = $files->getMimeType();
This time, it didn't work either. So, how can I get the MIME type ?
Thank you so much for your help
I believe $files
in both of your snippets would just be a simple array
, and each element should contain a key to indicate the type, like so:
$files = $adapter->getFileInfo();
foreach ($files as $file) {
// Print the MIME Type for $file
echo $file['type'];
}
The Zend_File_Transfer_Adapter_Abstract
class defines the code for determining the MIME type. It depends on Fileinfo
class/extension or the mime_content_type()
function (part of an older version of Fileinfo
, I believe).
http://us2.php.net/manual/en/book.fileinfo.php
PHP 5.3 includes Fileinfo
by default. Versions prior to 5.3 require the use of the PECL extension:
http://pecl.php.net/package/Fileinfo
精彩评论