我使用mime_content_type()函數進行文件上傳,本地主機它正常工作,但它表現出一些錯誤在線文件mime_content_type()函數不工作
Fatal error: Call to undefined function mime_content_type()
我使用mime_content_type()函數進行文件上傳,本地主機它正常工作,但它表現出一些錯誤在線文件mime_content_type()函數不工作
Fatal error: Call to undefined function mime_content_type()
您必須對mime_magic擴展。檢查你的php.ini並查看phpinfo()。順便說一句,這個函數已被棄用,因爲PECL擴展Fileinfo以更清潔的方式提供了相同的功能(以及更多)。
Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.
The libmagic library is bundled with PHP, but includes PHP specific changes. A patch against libmagic named libmagic.patch is maintained and may be found within the PHP fileinfo extensions source.
更新:
mime_content_type()
不再過時,PHP7對這一功能的支持了。
早期版本我的回答:
mime_content_type()
is deprecated, probably because [fileinfo][1] can give you those information about the file and more.You can use finfo() like shown below,
function _mime_content_type($filename) { $result = new finfo(); if (is_resource($result) === true) { return $result->file($filename, FILEINFO_MIME_TYPE); } return false; }
finfo是一個pecl擴展名,所以如果沒有安裝擴展名將無法工作 – Okneloper 2016-04-13 08:15:40
@Okneloper不再是從安裝文檔中提取出來的東西「'這個擴展在PHP 5.3.0之前是默認啓用的,在此之前,fileinfo是一個PECL擴展,但不再維護那裏「http://php.net/manual/en/fileinfo.installation.php – Rao 2016-04-14 10:07:50
但5.6的安裝我測試它給了我一個」致命的錯誤:類'finfo'不是發現「 – Okneloper 2016-04-14 10:55:15
很有可能丟失\ PHP \演員\ magic.mime文件。
http://www.php.net/manual/en/fileinfo.installation.php - >閱讀第一條評論的第一行。 – 2013-02-11 09:19:32
另請注意,該功能已棄用:http://php.net/mime_content_type改爲使用http://www.php.net/manual/en/ref.fileinfo.php。 – 2013-02-11 09:20:16
在PHP 5.3.0之前,只有通過PECL fileinfo擴展才能使用mime_content_type() - 您運行的是哪個版本的PHP? – 2013-02-11 09:21:14