php - Firefox 仅通过 php 读取 pdf 一次
问题描述
通过单击按钮,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。我玩过“缓存控制”,但没有任何帮助。
可能是什么问题?
解决方案
问题是只有 Firefox 需要 ob_clean 和 flush 命令。将代码更改为:
header('Content-type: application/pdf');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
现在它可以工作了。
推荐阅读
- r - 在 R 中有一种方法可以使用带有任意参数的 pivot_longer 作为 cols 规范
- regex - 如何在powershell中使用多行正则表达式从文本文件中提取内容?
- python - PIL 和 tkinter 错误:TypeError:预期的 str、字节或 os.PathLike 对象,而不是列表
- r - R语言中“@”运算符的含义?
- mysql - 使用正则表达式返回不同的记录
- javascript - 如何将路径参数传递给html表单
- c++ - 检查队列是否按升序排序挂起
- c++ - 如何确定一个数组是否是 O(log N) 中 1-N 的排列?
- python - 没有窗口打开的调度程序浏览器任务
- python - 虚拟环境不适用于 pycharm 和 jupyterN