= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { return 'image/jpeg'; } if ($len >= 3 && substr($test, 0, 3) == 'GIF') { return 'image/gif'; } if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") { return 'image/png'; } return 'application/octet-stream'; }