llazzaro llazzaro - 1 year ago 139
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download