关注
Erlo

一个检查文件类型的方法

2023-02-10 10:09:22 发布   184 浏览  
页面报错/反馈
收藏 点赞
function checkFile(){
   $file = fopen($this->tmp_name, "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 8075:  
         $fileType = 'zip';break;  
      case 255216:  
         $fileType = 'jpg';break;  
      case 7173:  
         $fileType = 'gif';break;  
      case 6677:  
         $fileType = 'bmp';break;  
      case 13780:  
         $fileType = 'png';break;  
      default:  
         $fileType = $typeCode;  
   }
   //Fix  
   if ($strInfo['chars1']=='-1' AND $strInfo['chars2']=='-40' ) $fileType='jpg';  
   if ($strInfo['chars1']=='-119' AND $strInfo['chars2']=='80' ) $fileType='png';
   if($fileType && strpos(implode(',',$this->imgTypes),$fileType)){
      $this->fileType=$fileType;
      $this->fileImg=true;
      return true;
   }
  }


登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认