ファイルのバイナリチェック
完璧ではない
クライアントサイド
サーバサイド
code:ruby
def png?(file)
signature = file.read(4).chars.map{ _1.ord.to_s(16).upcase }.join
signature.start_with? "89504E47"
end
ローカルで見る時
hexdumpも便利
code:shell
$ hexdump test.jpg | head -n 1
0000000 ff d8 ff e1 03 7e 45 78 69 66 00 00 4d 4d 00 2a
参考