I have a script that's uploading a file to my server, and it works just fine. What I want to be able to do is test to see if that file is a JPEG, because I only want it to be a JPEG. The form variable is only something like /tmp/VSJHKHererl. So I can't use that. Any suggestions?
Try this function ImageTypes();
http://www.php.net/manual/en/function.imagetypes.php
Nick
There is another field that contains the original filename. Use that to find the extention (.jpg .jpeg .txt etc)
Read this page: http://www.php.net/manual/en/features.file-upload.php
Not a Mac user myself, but I've noticed that people who use them tend to leave off important things like .jpg in the file names. A more universal approach would be to check the extension of the file first, and then the MIME type if the first check comes back negative.
Extentions are nice, but the true filetype is store in the file itself. Most files begin their content with a short description of what they are. Perhaps as a'last resort' you could open the file itself and see what's in it.
Ah yes, one of the wonders of *nix is magic 🙂
I'd hate to have the overhead of a pipe out to magic every time I wanted to check a file but it'd be a great way of identifying something when all else failed.
a simple
$aFileType = file /path/to/file; would do. Expensive but reliable. :-)
file /path/to/file