Why is mime_content_type() deprecated in PHP?

I'm just curious to know why mime_content_type() is now considered deprecated.

This method for determining the mime type is much easier than the replacement Fileinfo functionality.


I guess it's because Fileinfo can return more information about files.

EDIT: Here is a replacement hack:

function _mime_content_type($filename) {
    $result = new finfo();

    if (is_resource($result) === true) {
        return $result->file($filename, FILEINFO_MIME_TYPE);

    return false;

The method is not deprecated!

It once was incorrectly marked as deprecated in the manual, but it has been fixed https://bugs.php.net/bug.php?id=71367 on the 14th of January 2016. However, at the moment, it is still incorrectly marked deprecated in the German, Spanish and Chinese manual.

Feel free to use mime_content_type() whenever you like :).

Another way is to pass to the constructor constant FILEINFO_MIME.

$finfo = new finfo(FILEINFO_MIME);
$type  = $finfo->file('path/filename');

Using finfo_file and finfo_open, and FILEINFO_MIME_TYPE:

finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $filename );

Here's a small wrapper to cover different PHP environments, derived from CSSMin.php in MediaWiki 1.20.0:

function getMimeType( $filename ) {
        $realpath = realpath( $filename );
        if ( $realpath
                && function_exists( 'finfo_file' )
                && function_exists( 'finfo_open' )
                && defined( 'FILEINFO_MIME_TYPE' )
        ) {
                // Use the Fileinfo PECL extension (PHP 5.3+)
                return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath );
        if ( function_exists( 'mime_content_type' ) ) {
                // Deprecated in PHP 5.3
                return mime_content_type( $realpath );
        return false;

EDIT: Thanks @Adam and @ficuscr for clarifying that this function was, in fact, not deprecated.

As of MediaWiki 1.30, the above code was essentially changed (back) to:

function getMimeType( $filename ) {
        return mime_content_type( $filename );

This works:

if (!function_exists('mime_content_type')) {

    function mime_content_type($filename)
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $mimeType = finfo_file($finfo, $filename);

        return $mimeType;

Need Your Help

How to get email body, receipt, sender and CC info using EWS?

c# asp.net exchange-server exchangewebservices

Can anyone tell me how to get an email body, receipt, sender, CC info using Exchange Web Service API? I only know how to get subject.

Appending a line to a file only if it does not already exist

linux sed terminal

I need to add the following line to the end of a config file: