在过去的几个小时里,这让我很难过。
// 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 类型不起作用。有什么建议么?