Вот реализация функции, описанная Wrikken
function getImgType($filename) {
$handle = @fopen($filename, 'r');
if (!$handle)
throw new Exception('File Open Error');
$types = array('jpeg' => "\xFF\xD8\xFF", 'gif' => 'GIF', 'png' => "\x89\x50\x4e\x47\x0d\x0a", 'bmp' => 'BM', 'psd' => '8BPS', 'swf' => 'FWS');
$bytes = fgets($handle, 8);
$found = 'other';
foreach ($types as $type => $header) {
if (strpos($bytes, $header) === 0) {
$found = $type;
break;
}
}
fclose($handle);
return $found;
}