Home >Backend Development >PHP Tutorial >How to get the mime type of a file in PHP? (code example)
In PHP, you can use the built-in function mime_content_type() function to obtain the mime type of the file. The following article will take you to understand the mime_content_type() function and see how the mime_content_type() function obtains the mime type of the file. .
me_content_type() function is a built-in function in PHP that is used to obtain the MIME content type of a file.
Basic syntax:
string mime_content_type($file)
Parameters: The me_content_type() function accepts a single parameter $file, which specifies what to look for File path for MIME details.
Return value: The me_content_type() function returns the MIME content type; if it fails, it will return false.
Example:
The following are some files in the demo directory. Let’s use the me_content_type() function to get the mime types of these files:
Implementation code:
<?php // 输出不同类型文件的结果 echo mime_content_type('demo/1.jpg') . "</br>"; echo mime_content_type('demo/2.png') . "</br>"; echo mime_content_type('demo/tp.psd') . "</br>"; echo mime_content_type('demo/index.html') . "</br>"; echo mime_content_type('demo/sqpurple.gif') . "</br>"; echo mime_content_type('demo/filename.txt') . "</br>"; echo mime_content_type('demo/demo.ppt') . "</br>"; echo mime_content_type('demo/filename.pdf') . "</br>"; echo mime_content_type('demo/filename.docx') . "</br>"; ?>
Output:
##Related video tutorial recommendation: "PHP Tutorial》
The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !The above is the detailed content of How to get the mime type of a file in PHP? (code example). For more information, please follow other related articles on the PHP Chinese website!