Php method for obtaining the object mime type

Source: Internet
Author: User
Tags mime file
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.