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.