PHP判断上传文件类型
生活随笔
收集整理的这篇文章主要介绍了
PHP判断上传文件类型
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
/*** 读取文件前几个字节 判断文件类型* @return string**/
function checkFileType($filename){$file=fopen($filename,'rb');$bin=fread($file,2); //只读2字节fclose($file);$strInfo =@unpack("c2chars",$bin);$typeCode=intval($strInfo['chars1'].$strInfo['chars2']);$fileType='';switch($typeCode){case 7790:$fileType = 'exe';break;case 7784:$fileType = 'midi';break;case 8297:$fileType = 'rar';break;case 255216:$fileType = 'jpg';break;case 7173:$fileType = 'gif';break;case 6677:$fileType = 'bmp';break;case 13780:$fileType = 'png';break;default:$fileType='unknown'.$typeCode;break;}if($strInfo['chars1']=='-1' && $strInfo['chars2']=='-40'){return 'jpg';}if($strInfo['chars1']=='-119' && $strInfo['chars2']=='80'){return 'png';}return $fileType;
}
总结
以上是生活随笔为你收集整理的PHP判断上传文件类型的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: k12教育发展前景 相关公司转型迫在眉睫
- 下一篇: PHP使用Twig