我让我的用户使用以下代码下载PDF文件:
$db->Record['file']包含文档的相对路径。
他们访问一个加载pdf的虚拟页面,所以他们实际上看不到url中的"text.pdf“。我更改了文件头,以实现以下目的:
$downloadfile = '/data/srv/www/vhosts/htdocs'.$db->Record['file'];
$filename = basename($downloadfile);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($downloadfile);下载没有任何问题,但当我尝试打开它时,出现以下错误:
The PDF file could not be openend, the type is not supported or the file
was damaged.我该如何解决这个问题呢?
不是:当我直接下载文件时,意味着要通过http://.../text.pdf访问并打开它,一切都很正常。
发布于 2010-09-01 23:09:51
(从评论中复制)我敢打赌,文件中一定有PHP错误消息。
发布于 2010-09-01 19:18:47
浏览器可能无法判断从文件中读取的预期长度。在php documentation中,尝试在标题中添加文件大小:
header('Content-Length: ' . filesize($file));发布于 2018-02-27 23:04:57
您是否在第一行的htdocs之后遗漏了一个/?
https://stackoverflow.com/questions/3617405
复制相似问题