我有一个问题要问你。我想在我的网络浏览器上显示PDF。
此外,我编写了这段代码。它适用于Firefox,但不幸的是不适用于Chrome。
$content = file_get_contents($path);
var_dump($content);
header("Content-Disposition: inline; filename=$path");
header('Content-Transfer-Encoding: binary');
header("Content-type: application/pdf");
header("Cache-Control: private, must-revalidate, post-check=0, pre-check=0, public");
header("Pragma: public");
header("Accept-Ranges: bytes");
echo $content;
你能帮助我吗?
先感谢您!
var_dump()
标头前不能有a (除非您在不告知我们的情况下使用输出缓冲)。发送标头之前不得有任何输出。另外,如果您用于var_dump()
转储PDF的内容,这会引入周围的工件,这可能会导致大多数PDF查看器出现问题。
要进行故障排除,请尝试以下最小的工作示例:
<?php
$path = './path/to/file.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename='.$path);
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
readfile($path);
顺便说一句,通常也最好不要使用封闭的PHP标记(?>),以避免在文件末尾出现任何不必要的意外空格,这可能会引起问题。并为您的弦乐使用一种相当的标记'或'。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句