1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| header("Content-type: text/html; charset=utf-8"); function checkHex($img) { $status = 0; $tips = array( "0" => "文件没问题", "5" => "文件有毒", "-1" => "文件没有上传" ); if (file_exists($img)) { $resource = fopen($img, 'rb'); $fileSize = filesize($img); fseek($resource, 0); if ($fileSize > 512) { $hexCode = bin2hex(fread($resource, 512)); fseek($resource, $fileSize - 512); $hexCode .= bin2hex(fread($resource, 512)); } else { $hexCode = bin2hex(fread($resource, $fileSize)); } fclose($resource); if (preg_match("/(3c25.*?28.*?29.*?253e)|(3c3f.*?28.*?29.*?3f3e)|(3C534352495054)|(2F5343524950543E)|(3C736372697074)|(2F7363726970743E)/is", $hexCode)) { $status = 5; } } else { $status = -1; } return $tips[$status]; }
$rs = checkHex("du.png");
print_r($rs);
|