【发布时间】:2019-02-08 04:23:24
【问题描述】:
我是 PHP 新手。我正在尝试测试是否可以在 Apache 服务器上的目录中打开 PDF 文件。该目录没有 .htaccess。当我执行代码时,出现“加载 PDF 文档失败”错误。 $filePath 很好。任何想法将不胜感激。
$filePath = '/home/xxx/public_html/xFiles/Reports/Test.pdf';
if (file_exists($filePath)) {
echo "The file $filePath exists";
} else {
echo "The file $filePath does not exist";
die();
}
$filename="Test.pdf";
header('Content-type:application/pdf');
header('Content-disposition: inline; filename="'.$filename.'"');
header('content-Transfer-Encoding:binary');
header('Accept-Ranges:bytes');
readfile($filePath);
【问题讨论】:
-
你在标题之前有输出,这是不允许的