[英]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.