<?php/*@desc:获取图片真实后缀@param name 文件名@return suffix 文件后缀*/ function getimgsuffix($name) {$info = getimagesize($name);$suffix = false;if($mime = $info[‘mime‘]){$suffix = explode(‘/‘,$mime)[1];}return $suffix;}
$suffix = getimgsuffix(‘http://192.168.8.81/public/image/01.jpg‘);echo $suffix;
jpeg
<?php/*@desc:获取文件真实后缀@param name 文件名@return suffix 文件后缀*/ function getfilesuffix($name) {$file = fopen($name, "rb");$bin = fread($file, 2); // 只读2字节fclose($file);$info = @unpack("C2chars", $bin);$code = intval($info[‘chars1‘] . $info[‘chars2‘]);$suffix = "unknow";if($code == 255216){$suffix = "jpg";}elseif($code == 7173){$suffix = "gif";}elseif($code == 13780){$suffix = "png";}elseif($code == 6677){$suffix = "bmp";}elseif($code == 7798){$suffix = "exe";}elseif($code == 7784){$suffix = "midi";}elseif($code == 8297){$suffix = "rar";}elseif($code == 7368){$suffix = "mp3";}elseif($code == 0){$suffix = "mp4";}elseif($code == 8273){$suffix = "wav";}return $suffix;}
$suffix = getfilesuffix(‘http://192.168.8.81/public/image/01.jpg‘);echo $suffix;
jpg
如果觉得《php获取真实图片后缀》对你有帮助,请点赞、收藏,并留下你的观点哦!