【发布时间】:2011-05-24 21:31:30
【问题描述】:
在过去的几个小时里,这让我很困惑。
// Using just straight up FINFO detects the mime type
$oFileInfo = new finfo( FILEINFO_MIME_TYPE );
$sMimeType = $oFileInfo -> file($_FILES['myfile']['tmp_name'] );
// $sMimeType == 'application/pdf';
// Using Zend File Transfer... detects the mime type
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('MimeType', true, array('application/pdf'));
// $upload->getMimetype('myfile') == 'application/pdf'
// But when I try to validate it throws an exception
$upload->isValid('myfile');
// Throws
// [fileMimeTypeFalse] => File 'myawesomefile.pdf' has a false mimetype of 'application/octet-stream'
代码在 Apache、PHP 5.2 (Zend Server) 下运行良好,但现在在 Nginx、PHP-FPM、PHP 5.3 下运行。我很想使用 isValid() 方法来验证我上传的文件,但 mime 类型不起作用。有什么建议么?
【问题讨论】:
-
这取决于服务器,Linux 服务器通常可以工作,如果您使用 XAMPP 或 WAMP,它们通常会在配置中缺少一些东西
标签: php zend-framework zend-validate