「.rar」は「application/x-rar-compressed」「application/octet-stream」、
「.zip」は「application/zip」「application/octet-stream」です。
なお、それぞれのファイルのヘッダを調べる方法もあります。
zipファイルは「PK\001\002」「PK\003\004」「PK\005\006」のいずれか
rarファイルは「52 61 72 21 1A 07 00」
なので、下記のようにするとより厳密にチェックできるかもしれません。
lang
1// 最初の7バイトを取得
2$bytes = file_get_contents($file, FALSE, NULL, 0, 7);
3// 拡張子を取得
4$ext = strtolower(substr($file, -4));
5
6// rarファイルか否か
7if ( $ext == ".rar" ) {
8 if ( bin2hex($bytes) == "526172211a0700") ) {
9 echo "This is .rar file.";
10 }
11
12 // Zipファイルか否か
13 if ( $ext == ".zip" ) {
14 if substr($bytes, 0, 2) == "PK") {
15 echo "This is .zip file.";
16 }
17}