: This article describes how to obtain the object mime type in php. For more information about PHP tutorials, see. Php method for obtaining the object mime type
1. use the mime_content_type method
string mime_content_type ( string $filename )Returns the MIME content type for a file as determined by using information from the magic.mime file.
However, this method has been deprecated above php5.3. we recommend using the fileinfo method instead.
2. use the Fileinfo method (officially recommended)
To use fileinfo, you must install the php_fileinfo extension.
If the package has been installed, you can find php_fileinfo.dll (windows), fileinfo. so (linux) in the extension_dir directory)
Open php. ini, remove ";" Before extension = php_fileinfo.dll, and restart apache.
file('1.jpg');echo $mime_type; // image/jpeg?>
3. use the image_type_to_mime_type method (only Image types can be processed)
To use the exif_imagetype method, you must install the php_exif extension and the php_mbstring extension.
If it has been installed, you can find php_exif.dll (windows), exif. so (linux) in the extension_dir directory)
Open php. ini, and "," remove, and restart apache "before extension = php_mbstring.dll and extension = php_exif.dll.
Tips: If you use the suffix of the file name to determine whether the file suffix can be modified, it is inaccurate to use the suffix.
The above describes how to obtain the mime type of a file in php, including some content. I hope to help anyone who is interested in the PHP Tutorial.