I am trying to use the fileinfo extension to determine a file's mime type.
When I run the following code:
$file = $_FILES['file']['tmp_name'];
$fhandle = finfo_open(FILEINFO_MIME);
$mime = finfo_file($fhandle, $file);
if ($mime == 'image/jpeg')
echo "fileinfo determined this to be an image/jpeg";
but mime_type is not just the mime type (image/jpeg) but reads in full: "image/jpeg; charset=binary"
So the comparison seems to be failing because of the extra "; charset=binary."
I could take this string and just take the text before the semi-colon, but I heard that this extension could be used to fairly reliably check file types against known lists, so I think I may be overlooking some sort of formatting option for the finfo_file function, or something else altogether. Any thoughts on how to just capture "image/jpeg" into $mime_type instead of the full "image/jpeg; charset=binary" (I am not just looking for image files, I just used it as an example here.)
I checked php.net and didn't find any suggestions. Any thoughts from people here ?
Here is the extension on php.net, just in case anyone is curious (and would like to assist!): http://php.net/manual/en/book.fileinfo.php
It's a new extension as of php 5.3.