PHP cannot accurately identify MIMETypes after mimetype-Windows7 uploads files

Source: Internet
Author: User
I wrote a page for uploading FILES, the same file, the same Chrome (47.0.2526.20.m), the FILES uploaded under Windows8.1 $ _ FILES [& #039; myFile & #039;] [& #039; type & #039;] is very accurate. For example, a Word document with the value applicationvnd. openxmlformats... I wrote a page for uploading files, the same file, the same Chrome (47.0.2526.106 m), the files uploaded under Windows 8.1 $_FILES['myFile']['type']Is very accurate. For example, the value of a Word document is application/vnd.openxmlformats-officedocument.wordprocessingml.document
In Windows 7, the value obtained is application/octet-stream. In addition to this file, other types of files can be accurately identified by uploading through Windows 8.1, while all files uploaded through Windows 7 are application/octet-streamAnd cannot change the browser.

The form is also set with enctype:

Then I can see in the official PHP manual:

$_FILES['userfile']['type']
The MIME type of the file, if the browser provides this information. An example is "image/gif ". However, this MIME type is not checked on the PHP end, so do not take it for granted.

SinceThe browser provides this information, ThenWhy does the same browser have different performance in different systems?

P.S. I am now planning to use a third-party library to identify the MIME Types of a file, but I still want to know why this happens.

Reply content:

I wrote a page for uploading files, the same file, the same Chrome (47.0.2526.106 m), the files uploaded under Windows 8.1$_FILES['myFile']['type']Is very accurate. For example, the value of a Word document isapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
In Windows 7, the value obtained isapplication/octet-stream. In addition to this file, other types of files can be accurately identified by uploading through Windows 8.1, while all files uploaded through Windows 7 areapplication/octet-streamAnd cannot change the browser.

The form is also set with enctype:

Then I can see in the official PHP manual:

$_FILES['userfile']['type']
The MIME type of the file, if the browser provides this information. An example is "image/gif ". However, this MIME type is not checked on the PHP end, so do not take it for granted.

SinceThe browser provides this information, ThenWhy does the same browser have different performance in different systems?

P.S. I am now planning to use a third-party library to identify the MIME Types of a file, but I still want to know why this happens.

This parameter is completely dependent on browser identification. In some operating systems or file systems, MIME types can be obtained through convenient operations or information, but in some systems it may not be so easy, sometimes, to ensure the speed and reduce the cost of maintaining MIME recognition, the browser simply does not analyze the specific type. It is precisely because this parameter depends on the identification of the client, so this parameter is not always reliable. to be reliable, it is MIME or need to be identified by yourself.

The above answer is correct. The solution is to read the file header for analysis. You can use Baidu to find the file type for file header analysis. I will not paste it on Baidu.

Because different browsers do not completely output the same content during processing.

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.