我有一个 PDF 文件存储在本地主机的一个文件夹中,但在尝试查看文档时出现“”。
我的代码如下。我检查了完整的文件路径,如果我只是将文件路径复制并粘贴到我的浏览器上,我可以手动读取文件。
`if (file_exists($pdf_path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . basename($pdf_path) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($pdf_path));
ob_clean();
flush();
readfile($pdf_path);
exit;
} else {
// Send a 404 Not Found error and exit
header('HTTP/1.0 404 Not Found');
die('The requested file could not be found.');
}`
我尝试了其他答案,例如 this 和 Can't download PDF (FPDF) from PHP function 但都没有用。