I need to find what kind of file user have upload by checking binary data, and I found perfect solution for that, over here
Just to be specific this is the function I'm using:
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;
}
Now my question is, how can I get bits for other file types, like .zip, .exe, mp3, mp4
etc... if there is some kind of list somewhere out there it would be great, though I would like to extract it myself and learn how all of this really works.