RFC 1867
3.3 use of multipart/form-data
The definition of multipart/form-data is included in section 7. A
boundary is selected that does not occur in any of the data. (This
selection is sometimes done probabilisticly.) Each field of the form
is sent, in the order in which it occurs in the form, as a part of
the multipart stream. Each part identifies the INPUT name within the
original HTML form. Each part should be labelled with an appropriate
content-type if the media type is known (e.g., inferred from the file
extension or operating system typing information) or as application/octet-stream
http://www.php.net/manual/en/features.file-upload.post-method.php
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.
c/tcp/ip;10985369 wrote:
As well I'm a little confused as to why the browser would report a different mime type if it is not explicitly renamed.
First off, what you call "browser" may not be a browser at all. It might just as well be a PHP script I wrote to upload 'nasty_stuff.exe' while supplying a content-type value of "fluffy bunnies". NEVER trust data from any outside source. You can make no assumptions that the outside is benevolent, and neither can you assume the outside is correct.
Secondly, a use may have named their CSV file 'values.txt', which doesn't means it's not a CSV file, just that it's extension is something else. Unless the browser analyzes the file contents, there is no way it can tell you that the file is "text/csv". It is however likely to claim the file to be "text/plain".
Thirdly, even if the browser wants to supply the best possible mime type values that it can, it may not be able to correctly do so for various reasons. For example, while IE might be able to correctly determine that a given file is an excel file, an earlier versin of IE might not, if excel has changed its file format since then. The programmers of a non IE-browser may not be able retrieve information on all the various formats that excel has ever had since 1985 (Mac) or 1987 (Windows).
Also, for browsers to be able to handle sniffing of all mime type formats, they'd be a lot heavier programs. Personally, I want a browser to browse the web and nothing else, just like I want an MP3-player to play MP3s and NOT browse the web (thank you Winamp 2.09a). So in the end, even if some/all browsers did this, I'd sure as hell make sure I had another browser to use, even if it meant developping it myself and you'd once again not be able to trust the 30GB "intelligent" browsers.
And in the end, even if all browsers correctly did all of this, making you extremely trusting, remember that I could still send you a file of type "fluffy bunnies that we all love so much"...
Finally, since it's impractical for browsers to properly do the job, I don't reallt see why they should at all. Sure, it's nice of them so tell you that .json is application/json, .txt is plain/text etc for common formats, but since you can't
1. trust this information
2. just as easily check the file extension yourself
3. are likely to know exactly what a format is if you want to handle it, which also means YOU are able to actually validate that the file is in this format
... I don't really see why they should supply the value to begin with.