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.

Syntax:

string mime_content_type( $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.

Below programs illustrate the mime_content_type() function in PHP:

Program 1:
Original Image:
https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to illustrate mime_content_type function
  
echo mime_content_type('gfg.png') . "</br>";
?>

chevron_right


Output:

image/png

Program 2:
Original Image:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to illustrate 
// mime_content_type function
  
// Providing and print result of different kind of files 
echo mime_content_type('/home/rajvir/Desktop/gfg.png') . "</br>";
echo mime_content_type('/home/rajvir/Desktop/gfg_Article.html') . "</br>";
echo mime_content_type('/home/rajvir/Downloads/gfg.gif') . "</br>";
echo mime_content_type('/home/rajvir/Desktop/gfg_contribute.txt') . "</br>";
echo mime_content_type('/home/rajvir/Downloads/geeks.ppt') . "</br>";
echo mime_content_type('/home/rajvir/Downloads/geeks.pdf') . "</br>";
  
?>

chevron_right


Output:

image/png
text/plain
image/gif
text/plain
application/vnd.ms-powerpoint
application/pdf

Reference: http://php.net/manual/en/function.mime-content-type.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : ManasChhabra2



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.