【发布时间】:2014-08-28 08:01:35
【问题描述】:
我想使用此代码在浏览器中显示 PDF 文件
<?php
$file = './path/to/the.pdf';
$filename = 'Custom file name for the.pdf'; /* Note: Always use .pdf at the end. */
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
?>
该代码在 Firefox 中运行良好,但在 Chrome 中却不行。我还没有在任何其他浏览器中测试过。这是 Chrome 的错误吗?无论如何我可以让它显示在 Firefox 和 Chrome 中吗?
【问题讨论】:
-
好吧,chrome 会强制你的 pdf 下载吗?还有你为什么在readfile之前使用@?
-
可能是标题问题。
-
这段代码对我有用。您是否尝试过更新您的 chrome,或者在其他一些 comp 上尝试它?也许有一些插件可能会导致问题?
-
Chrome 不会强制下载 pdf,只是停留在加载图标上。用firefox没问题。
-
我遇到了完全相同的问题。我注意到它只发生在大于 64K 的 PDF 文件中。 chrome 控制台(网络)报告 Status Code:206 Partial Content...
标签: php google-chrome pdf