您好,欢迎访问一九零五行业门户网

php 判断图片文件的真实类型

/** * * 检测文件的真实类型 * * @param string $srcpath 文件路径 * * @return string $realtype 文件真实类型 * */$imgurl = 'http://pic.babytree.com/foto3/thumbs/2015/0506/51/8/357557aa334dd03923a408f_nb.jpg';echo file_type_detect($imgurl);function file_type_detect($srcpath){ $types = array( 6677 => 'bmp', 7173 => 'gif', 7368 => 'mp3', 13780 => 'png', 255216 => 'jpg', ); $curl_obj = new curl(false); $binary = $curl_obj->get($srcpath); //$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;}
判断文件的真实类型
其它类似信息

推荐信息