我需要找到什麼樣的文件,用戶已經通過檢查二進制數據上傳,我發現那完美的解決方案,在here檢查二進制圖像數據
只要是特定的,這是我使用的功能:
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;
}
現在的問題是,如何才能得到位的其他文件類型,如.zip, .exe, mp3, mp4
等等......如果有某種列表的某處,這將是巨大的,但我想它提取我自己並瞭解所有這些如何真正起作用。
您是否嘗試過用['finfo_file'(http://www.php.net/manual/en/function.finfo-file.php)?順便說一句,爲什麼你不使用這個函數var_dump zip,exe等字節......? – j0k
[finfo_file(英文版)](http://www.php.net/manual/en/function.finfo-file.php) – GolezTrol
它只支持'PHP> = 5.3.0'我希望支持情人版本也是如此。 – Linas