Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 552
Josiah Avatar asked Aug 12 '09 02:08

Josiah


People also ask

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

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. Return Value: This function returns the MIME content type or False on failure.

What is MIME type of a file?

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

What is the MIME type for pdf?

The main MIME media type for PDF is application/pdf. This type is defined by RFC 8118 and is the responsibility of ISO TC 171 SC 2 WG 8. It was last updated in March 2017, prior to the original publication of PDF 2.0, so the PDF Association is proposing a minor refresh and update in the upcoming May 2022 ISO meetings.


2 Answers

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 :).

like image 136
Adam Avatar answered Oct 06 '22 03:10

Adam


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; } 
like image 38
Alix Axel Avatar answered Oct 06 '22 03:10

Alix Axel