[英]Cannot open PDF file downloaded using php
我正在使用以下php代码下载pdf文件。 我可以下载pdf文件,但无法打开它。 我做错了什么? 谁能帮我?
download.php
<?php
$file = 'Rev.pdf';
$filepath = "doc/" . $file;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream; charset=utf-8');
header('Content-Disposition: attachment; filename='.basename($filepath));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
ob_clean();
flush();
readfile($filepath);
exit;
?>
更新2:
以下是我的HTML
<a href="download.php">download</a>
更新3:已解决
首先,我想说声对不起,给您带来麻烦。 我已经解决了这个问题。 实际上我的PDF文件本身已损坏。 因此,我创建了新的pdf文件,并且运行良好。 再次感谢大家听到我的问题并提出建议。
代替
header('Content-Type: application/octet-stream; charset=utf-8');
尝试这个
header('Content-Type: application/pdf');
还请查看以下内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.