1. 程式人生 > >finfo_open函數不支持,通過二進制流獲取文件類型

finfo_open函數不支持,通過二進制流獲取文件類型

jpg fun bmp gpo png ria open ret from

    public function getMime()
    {
        // $finfo = finfo_open(FILEINFO_MIME_TYPE);
        // return finfo_file($finfo, $this->filename);

        $fp=fopen($this->filename,‘r‘);///實際是image/png
        $bin = fread($fp, 2); //只讀2字節
        fclose($fp);
        $str_info = @unpack("C2chars", $bin
);//Unpack data from binary string $type_code = intval($str_info[‘chars1‘].$str_info[‘chars2‘]);// Get the integer value of a variable $file_type = ""; switch ($type_code) { case 7790: return $file_type = ‘exe‘; break; case
7784: return $file_type = ‘midi‘; break; case 8075: return $file_type = ‘zip‘; break; case 8297: return $file_type = ‘rar‘; break; case 255216: return $file_type = ‘jpg‘;
break; case 7173: return $file_type = ‘gif‘; break; case 6677: return $file_type = ‘bmp‘; break; case 13780: return $file_type = ‘png‘; break; default: return $file_type = ‘unknown‘; break; } }

finfo_open函數不支持,通過二進制流獲取文件類型