Click to See Complete Forum and Search --> : how to read the bytes that make up a file?


jasongr
05-10-2005, 10:03 AM
Hello

I have a file which the user uploads
The file should be of type jpeg
I would like to ensure that the uploaded file has indeed the correct header format of jpeg: '\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46'

I need some way to read the first set of bytes that make up the file
and then to compare them to the correct header of
'\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46'

does anyone know how I can read these bytes and perform the comparison?

thanks in advance

bokeh
05-10-2005, 10:29 AM
$mime_type = mime_content_type($uploaded_file);
print $mime_type; //should output image/jpeg for a .jpg file

jasongr
05-10-2005, 10:33 AM
This only works on Windows
Also I am not sure how this function is implemented
I hope it doesn't base its returned value on the file extension.
My tests needs to be more intelligent than that
This is why I am trying to compare bytes from the file header

bokeh
05-10-2005, 12:39 PM
To find out more look at this. http://www.php.net/mime_content_type

jasongr
05-10-2005, 01:38 PM
here (http://forums.devnetwork.net/viewtopic.php?p=173387#173387) is a solution