mime_content_type() function not defined

后端 未结 6 1883
有刺的猬
有刺的猬 2021-01-03 21:33

I am using the mime_content_type() function for file upload, it works fine on localhost however I\'m encountering the following error on my live server:

相关标签:
6条回答
  • 2021-01-03 22:04

    If you are on shared hosting, chances are that the fileinfo PHP extension is either not enabled or installed.

    In the case where it's not enabled, navigate to the Software section of CPanel (consult documentation of your control panel if you're not using CPanel) and click Select PHP Version (or something related to that) and enable the extension by checking its box and saving your action.

    If it's not installed, the extension won't be part of the PHP extensions at cPanel > Software > Select PHP Version > Extensions, edit your php.ini file and uncomment extension=php_fileinfo.dll if you're on Windows. Consult your hosting provider's docs if any of these don't work.

    0 讨论(0)
  • 2021-01-03 22:10

    I changed my php version from 7.1 to 5.6 it works for me

    0 讨论(0)
  • 2021-01-03 22:16

    Likely missing \php\extras\magic.mime file.

    0 讨论(0)
  • 2021-01-03 22:19

    Update:

    mime_content_type() is no longer deprecated, php7 has support for this function now.

    Earlier version of my answer:

    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

    0 讨论(0)
  • 2021-01-03 22:20

    You must have the mime_magic extension on. Check your php.ini and look in phpinfo(). By the way this function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.

    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

    0 讨论(0)
  • 2021-01-03 22:23

    PHP 7

    1. Edit your php.ini file and uncomment extension=php_fileinfo.dll.

    2. Restart your HTTP server (e.g. Apache).

    3. echo mime_content_type($path_absolute.$file);//Outputs: application/pdf

    0 讨论(0)
提交回复
热议问题