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教育发展前景 相关公司转型迫在眉睫
- 下一篇: 中信银行动卡空间怎么看额度