Firefox仅通过php阅读pdf

问题描述 投票:0回答:1

通过单击按钮,PDF文档将以另一种固定形式显示。 php文件看起来像:

// filename is read_pdf.php

    $path = '../../pdfs';
    $code = filter_input(INPUT_GET, 'ac', FILTER_SANITIZE_NUMBER_INT);

    if (isset($antcode) ) {

        $a = ... get the pdf-name from a mysql db as a function auf $code;

        $file = $path . '/' . $a;
    // Header content type 
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="' . $a . '"');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: ' . filesize($file));
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');
        header('Accept-Ranges: bytes');

        @readfile($file);
    }

在jQuery中,我开始文件读取过程:

var url ="php/read_pdf.php?ac=" + r.randid;
window.open(url,'_blank');  

Chrome的一切进展顺利。在Firefox中,它可以与'localhost'正常工作。但是在服务器上,Firefox设法一次读取了pdf。在下一个pdf中,不再加载任何其他内容。如果删除缓存,则可以再次正确加载一个pdf。我玩过“ Cache-Control”,但没有帮助。

可能是什么问题?

php pdf firefox readfile window.open
1个回答
0
投票

问题是,只有Firefox需要ob_clean和flush命令。将代码更改为:

 header('Content-type: application/pdf');    
 header('Content-Length: ' . filesize($file));
 ob_clean();
 flush();
 readfile($file);

现在可以使用。

© www.soinside.com 2019 - 2024. All rights reserved.