Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mime_content_type() function not defined

Tags:

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:

Fatal error: Call to undefined function mime_content_type()

like image 597
user1898114 Avatar asked Feb 11 '13 09:02

user1898114


People also ask

How can I get MIME type from uploaded file in PHP?

PHP | mime_content_type() function. The mime_content_type() function is an inbuilt function in PHP which is used to get the MIME content-type of a file. Parameters: This function accepts single parameter $file which specifies the path of the file which MIME details to be find.

What is a mime in PHP?

MIME stands for "Multipurpose Internet Mail Extensions. It's a way of identifying files on the Internet according to their nature and format. For example, using the "Content-type" header value defined in a HTTP response, the browser can open the file with the proper extension/plugin.


3 Answers

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

like image 107
Nagendra Rao Avatar answered Sep 19 '22 06:09

Nagendra Rao


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

like image 33
Techie Avatar answered Sep 20 '22 06:09

Techie


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.

like image 26
Nayi Avatar answered Sep 21 '22 06:09

Nayi