PHP 判断图片文件的真实类型
PHP 判断图片文件的真实类型代码:
<? $imgurl = 'https://www.yuanxiapi.cn/api/ipimg/'; echo file_type_detect($imgurl); function file_type_detect($srcPath){ $types = array( 6677 => 'bmp', 7173 => 'gif', 7368 => 'mp3', 13780 => 'png', 255216 => 'jpg', ); $binary=file_get_contents($srcPath); $bytes = substr($binary, 0, 2); $head = @unpack('C2char', $bytes); $typeCode = intval($head['char1'].$head['char2']); $realType = isset($types[$typeCode]) ? $types[$typeCode] : $typeCode; return $realType; } ?>
评论
发表评论: