//by www.qzphp.cn function checkHex($img_path) { if (file_exists($img_path)) { $resource = fopen($img_path, 'rb'); $fileSize = filesize($img_path); fseek($resource, 0); //把文件指针移到文件的开头 $hexCode = bin2hex(fread($resource, $fileSize)); fclose($resource); /* 匹配16进制中 <?php ?>|eva l|fputs|fwrite */ if (preg_match("/(3c3f706870.*?3f3e)|(6576616c)|(6670757473)|(667772697465)/is", $hexCode)) return true; else return false; } else { return false; } }