php - 在php中下载pdf文件代码

标签 php pdf

$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/

相关文章:

android - itext 旋转 pdf 文档但不旋转图像

HTML 到 PDF A4 可打印尺寸

pdf - Watin 和 PDF 的

java - 压缩使用 itext 创建的 pdf 文件

php - 我可以在准备好的语句中参数化表名吗?

javascript - 停止在我们的自定义注册表上注册垃圾邮件

php - 从ftp上传到显示http需要多长时间?

php - 使用PHP将Access数据导入MySQL

java - 有没有可以从给定坐标中提取文本的PDF解析库?

php - 如何在 woocommerce 中获取带有 billing_* 的所有字段?