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-stream
And 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-stream
And 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.