[英]php pdf download - can't open the downloaded file correctly
在我的网页上可以下载pdf文件(285kB)。 问题是您以pdf格式下载了该网站,而不是我要下载的pdf文件。
因此,我无法使用Adobe Reader打开下载的pdf,但必须使用记事本打开文件,并且内容为
<!DOCTYPE html><html lang="en"><he...
这是下载文件的代码:
$filepath = "/download/";
$filename = "filename";
header('Content-disposition: attachment; filename='.$filename);
header('Content-type: application/octet-stream' );
header('Content-Length: '. filesize($filepath.$filename));
readfile($filepath.$filename);
exit;
你能帮助我吗?
抱歉,由于我的声誉低下,我无法发表评论。 这就是为什么张贴作为答案。 您可以尝试
header('Content-type: application/pdf' );
header('Content-disposition: attachment; filename='.$filename.'.pdf');
header('Content-disposition: attachment; filename='.$filename.'.pdf');
您是否在扩展名中添加了文件名? 像这样...
$filename = "filename.pdf";
$filepath = "/download/".$filename;
if (file_exists($filePath) {
header('Content-Disposition: attachment; filename='.basename($filepath));
header('Content-type: application/zip' );
header('Content-Length: '. filesize($filePath));
readfile($filepath);
exit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.