zoukankan      html  css  js  c++  java
  • 判断文件图片类型,

    $type  = $_FILES['image']['tmp_name'];//文件名
    //$type  = $this->getImagetype( $type ); 
    $filetype = ['jpg', 'jpeg', 'gif', 'bmp', 'png'];
    if (! in_array($type, $filetype))
    { 
     return "不是图片类型";
    }
    
    //*判断图片上传格式是否为图片 return返回文件后缀
    public function getImagetype($filename)
    {
     $file = fopen($filename, 'rb');
     $bin = fread($file, 2); //只读2字节
     fclose($file);
     $strInfo = @unpack('C2chars', $bin);
     $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
     // dd($typeCode);
     $fileType = '';
     switch ($typeCode) {
      case 255216:
       $fileType = 'jpg';
       break;
      case 7173:
       $fileType = 'gif';
       break;
      case 6677:
       $fileType = 'bmp';
       break;
      case 13780:
       $fileType = 'png';
       break;
      default:
       $fileType = '只能上传图片类型格式';
     }
     return $fileType;
    }
    

      

  • 相关阅读:
    mangoDB
    python文档
    单例模式
    celery
    flask 部署
    json
    Docker+Jenkins+Go完成自动化部署
    Go多协程循环打印ABAC
    正则表达式
    从零开始学Go之并发(四):互斥
  • 原文地址:https://www.cnblogs.com/guoyachao/p/11225467.html
Copyright © 2011-2022 走看看