Mimetype-windows 7 PHP does not accurately recognize MIME Types after uploading a file

Source: Internet
Author: User
I wrote an upload file page, the same file, the same Chrome (47.0.2526.106 m), uploaded files under Windows 8.1 $_FILES['myFile']['type']is accurate, such as a Word document with a value of application/vnd.openxmlformats-officedocument.wordprocessingml.document
And in Windows 7 uploads, the resulting value is application/octet-stream。 In addition to this file, other types of files can be accurately identified through Windows 8.1 uploads, while uploading via Windows 7 is application/octet-stream, but not for the browser.

The form also sets the enctype:

Then I 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 side, so do not assume this value is assumed.

Since it is 浏览器提供此信息 , Why do the same browsers behave differently under different systems?

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

Reply content:

I wrote a page to upload the file, the same file, the same Chrome (47.0.2526.106 m), the file uploaded under Windows 8.1 $_FILES['myFile']['type'] is very accurate, such as a Word document, whose value is application/vnd.openxmlformats-officedocument.wordprocessingml.document
And in Windows 7 uploads, the resulting value is application/octet-stream . In addition to this file, other types of files through the Windows 8.1 upload can be accurately identified, and through the Windows 7 upload application/octet-stream , but also do not change the browser.

The form also sets the enctype:

Then I 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 side, so do not assume this value is assumed.

Since it is 浏览器提供此信息 , Why do the same browsers behave differently under different systems?

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

This parameter depends entirely on the browser identification, in some operating systems or file systems, there is convenient operation or information to get to MIME type, and in some systems may not be so easy, and the browser sometimes to ensure speed, also reduce the cost of maintaining MIME recognition, simply do not analyze the specific type. It is also because this parameter relies on the client's recognition, so this parameter is not always reliable, to be reliable is mime, or need to identify themselves.

The above answer is correct, the solution is to read the file header analysis, you can Baidu find the file header analysis file type, specific I do not Baidu paste.

Because different browsers do not completely output the same content when they are processed.

  • Related Article

    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.