問題 ファイルの内容の種類を、マジックナンバーをを見て判定したい。 (フォーマット識別子、マジックバイト) 答え 自作するとこんな感じ。 <?php function gazoHantei($filename) { //先頭数文字を取得する.巨大なファイルでも先頭だけ見る. $magic = file_get_contents($filename, false, null, 0, 12); $type = ''; if (strpos($magic, 'GIF') === 0) { //GIF87a,GIF89a $type = 'GIF'; } else if (strpos($magic, "\x89" . 'PNG') === 0) { $type = 'PNG'; } else if (strpos($magic, "\xFF\xD8") === 0) { //FF D8 DD E