2013-02-11 201 views
11

我使用mime_content_type()函數進行文件上傳,本地主機它正常工作,但它表現出一些錯誤在線文件mime_content_type()函數不工作

Fatal error: Call to undefined function mime_content_type()

+4

http://www.php.net/manual/en/fileinfo.installation.php - >閱讀第一條評論的第一行。 – 2013-02-11 09:19:32

+1

另請注意,該功能已棄用:http://php.net/mime_content_type改爲使用http://www.php.net/manual/en/ref.fileinfo.php。 – 2013-02-11 09:20:16

+0

在PHP 5.3.0之前,只有通過PECL fileinfo擴展才能使用mime_content_type() - 您運行的是哪個版本的PHP? – 2013-02-11 09:21:14

回答

11

您必須對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.

Read more

10

更新

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; 
} 

Ref: https://stackoverflow.com/a/1263977/1161412

[1]: http://php.net/manual/en/class.finfo.php

+2

finfo是一個pecl擴展名,所以如果沒有安裝擴展名將無法工作 – Okneloper 2016-04-13 08:15:40

+1

@Okneloper不再是從安裝文檔中提取出來的東西「'這個擴展在PHP 5.3.0之前是默認啓用的,在此之前,fileinfo是一個PECL擴展,但不再維護那裏「http://php.net/manual/en/fileinfo.installation.php – Rao 2016-04-14 10:07:50

+0

但5.6的安裝我測試它給了我一個」致命的錯誤:類'finfo'不是發現「 – Okneloper 2016-04-14 10:55:15

0

很有可能丟失\ PHP \演員\ magic.mime文件。