llazzaro llazzaro - 3 months ago 40
PHP Question

PHP : binary image data, checking the image type

I have some images in bin, I want to check the header to check the format (jpg, png, etc)

I don't want to use temp files! I have a solution using TEMP FILES.


The bits start with:

$JPEG = "\xFF\xD8\xFF"
$GIF  = "GIF"
$PNG  = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
$BMP  = "BM"
$PSD  = "8BPS"
$SWF  = "FWS"

The other ones I wouldn't know right now, but the big 3 (jpeg,gif,png) usually cover 99%. So, compare the first bytes to those string, and you have your answer.