$path = BASE_URL."/pdf/";
$filename= $path.basename($_GET['download_file']);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment;
filename='.basename($filename));
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename));
readfile($filename);
exit;
此代码有效,但打开下载的 pdf 时出现读取 pdf 文件时出错
。在上面的代码中,我从位置 http://localhost//eec//pdf/CV_Prabin Mishra.pdf
最佳答案
BASE_URL
末尾可能有一个斜杠,因此您不需要额外的斜杠:
$path = BASE_URL."pdf/";
关于php - 在php中下载pdf文件代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13833146/