I am trying to use the fileinfo extension to determine a file's mime type.
When I run the following code:
but mime_type is not just the mime type (image/jpeg) but reads in full: "image/jpeg; charset=binary"
$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";
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.)