PHP upload file types
- Started
- Last post
- 10 Responses
- kinetic
is there anything out there that has a decent list of files and what their type will be listed as to PHP when that file is uploaded?
for instance..trying to figure out how PHP will handle auto cad files.
also, files show up as different types on different platforms (ie - on PC jpg is one thing and on MAC it is listed as another type)
also, another question. if i dont have excel on my computer and i upload an excel file, the type is not registered so checking for it is pointless. obviously most people who would upload the excel file would have it on their computer, but what about the slim chance that they dont...how do you deal with that?
thanks for ya help :) appreciate some input on this :D
- jox0
Amazing.. I was just going to ask the same thing!
Have you been reading my mind?
- ribit0
What is this used for? I thought all the file type registration is specific to the computer doing the uploading, and that uploaded files would be recognised only on extension?
- enobrev0
as one of the comments in the first manual link states, they're easy to fake. also, I've seen that different browsers send different mime types as well (which I always found strange).
The most fully reliable means of knowing a file's type is to read the actual binary file headers. I recall seeing some php project to do just that some time ago, but it was a very heavy task with big fat files. And those were mostly audio and video files. If i find a link, I'll post it.
For the most part you can rely on the mime type you get by the normal php functions, but test with all browsers to see that they are reporting the same mime types, and be prepared for spoofed ones.
- kinetic0
damn, i forgot i posted this till today when the project regarding this issue re-surfaced
thanks for the respones all
enobrev...a question.
how could someone send a fake file type?we thought of checking the extension after the dot but it didn't seem like a really tight solution.
a confusing issue
- kinetic0
ribit..i dont think thats the case.
if you take a word doc for instance and rename it to yourworddocname.GIF .. when you check the type with php, it will still be listed as the type word doc
- kinetic0
bump++;
- mitsu0
you need to know how to read the headers in the particular file you anticipate to be uploaded. ever file type has it's own unique type of
header.however, that type of validation is overkill. there's usually little need to check for these types of inconsistencies.
just using the extension should be adequate.
- mike0
Google... three word search, first result.
http://www.webmaster-toolkit.com…
you can build an array of the types you want to work with and then check the type passed with in_array().
or... you could make a tab delimited list from this list and push that into an array if you like. then you know the proper headers to send across.
if you are working with images on the upload, you can call getimagesize() and determine the absolute image type from the return array.
- kinetic0
wicked, thanks mike :)