In PHP, mime type is a multi-purpose Internet mail extension type. It is an Intel standard for describing message content types. It is designed to attach multimedia data when sending emails. PHP can use "mime_content_type ()" function to get the mime type of the file.
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
1. Definition of MIME
MIME (Multipurpose Internet Mail Extensions) multipurpose Internet mail extension type. It is an Internet standard for describing message content types
2. The original purpose of MIME design
MIME means Multifunctional Internet Mail Extensions. The original purpose of its design is to Attach multimedia data when sending an e-mail so that the mail client can process it according to its type. However, when it is supported by the HTTP protocol, its significance becomes even more significant. It makes HTTP transfer not only ordinary text, but also rich and colorful.
3.MIME file format
Each MIME type consists of two parts, a large category and a type.
For example:
Hypertext Markup Language text.html text/html
Normal text.txt text/plain
PDF document.pdf application/pdf
PNG image.png image/png
TAR file.tar application/x-tar
4.PHP gets the MIME type of the file
You can use the built-in function mime_content_type() function in PHP to obtain the mime type of the file.
Basic syntax:
string mime_content_type($file)
Parameters: The me_content_type() function accepts a single parameter $file, which specifies the file path of the MIME details to be found .
Return value: The me_content_type() function returns the MIME content type; if it fails, it will return false.
Example:
Let’s use the me_content_type() function to get the mime type of these files (the files are in the demo directory):
Implementation code:
<?php # 输出不同类型文件的结果 echo mime_content_type('demo/1.docx') . "</br>"; echo mime_content_type('demo/1.html') . "</br>"; echo mime_content_type('demo/1.jpg') . "</br>"; echo mime_content_type('demo/1.pdf') . "</br>"; echo mime_content_type('demo/1.txt') . "</br>"; echo mime_content_type('demo/1.zip') . "</br>"; ?>
Output result:
inode/x-empty
inode/x-empty
image/jpeg
application/pdf
inode/x-empty
application/zip
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does mime type mean in php. For more information, please follow other related articles on the PHP Chinese website!