I wrote a page for uploading files. The same file, the same Chrome(47.0.2526.106 m), was uploaded under Windows 8.1
$_FILES['myFile']['type']Is very accurate, such as a Word document, its value is
In Windows 7, however, the value obtained was
application/octet-stream. In addition to this file, other types of files uploaded through Windows 8.1 can be accurately identified, while uploaded through Windows 7 are all
application/octet-stream, change the browser also not line.
The form is also set with enctype:
<form method="POST" enctype="multipart/form-data"> ... </form>
Then I was in PHPOfficial handbookInside saw:
The MIME type of the file, if the browser provides this information. One example is “image/gif”. However, this MIME type is not checked on the PHP side, so don’t take it for granted.
Since it is by
The browser provides this information, thenWhy do the same browsers behave differently under different systems?
P.s. I am now planning to use a third-party library to identify the MIME Types of files, but I still want to know why this happens.
This parameter depends entirely on browser identification. In some operating systems or file system inside, there are convenient operations or information to obtain MIME types, while in some systems inside may not be so easy. In order to ensure speed and reduce the cost of maintaining MIME identification, browsers sometimes simply do not analyze specific types. It is also because this parameter depends on the identification of the client, so this parameter is not always reliable. To obtain reliable MIME, you need to identify it yourself.