Chrome has “Failed to load PDF document” error message on inline PDFs

前端 未结 5 843
无人共我
无人共我 2020-12-07 02:15

I have a problem with reading pdf file in Chrome by using PHP.

The following code is how I do in PHP

$path = \"actually file path\";
header(\"Pragma:         


        
5条回答
  •  清歌不尽
    2020-12-07 02:34

    I had similar issue but I noticed the order matters. Seems that ; filename= must have quotes around it, Content-Disposition: attachment Try this:

        $file = "/files/test.pdf";
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $mime = finfo_file($finfo, $file);
    
        header('Pragma: public');
        header('Expires: 0');
        header('Content-Type: $mime');
        header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename="'.basename($file).'"'));
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Length' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
    

提交回复
热议问题