从php下载pdf文件 [英] Download pdf file from php

查看:145
本文介绍了从php下载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个向访问者发送PDF文件的文件。
我有file:download.php

这是他的内容:

  header('Content-disposition:attachment; filename ='。$ _ GET ['file']); 
header('Content-type:application / pdf');
readfile($ _ GET ['file']);

由于某些原因,该文件发送一个空的pdf文件183字节。



有什么建议吗?

谢谢。

解决方案

试试这个:

  header('Pragma:public'); //需要
header('Expires:0'); //缓存
header('Cache-Control:must-revalidate,post-check = 0,pre-check = 0');

header('Cache-Control:private',false);
header('Content-Type:application / pdf');
header('Last-Modified:'。gmdate('D,d M Y H:i:s',filemtime($ filepath))。'GMT');
header('Content-disposition:attachment; filename ='。$ pathinfo ['filename']。'.pdf');
头(Content-Transfer-Encoding:binary);
header('Content-Length:'。filesize($ filepath)); //提供文件大小
header('Connection:close');
readfile($ filepath);
exit();


I'm trying to make a file that send a pdf file to the visitor. I have file: download.php

and this is his content:

header('Content-disposition: attachment; filename='.$_GET['file']);
header('Content-type: application/pdf');
readfile($_GET['file']);

for some reason, the file sending an empty pdf file 183 bytes.

any advice?

thanks.

解决方案

Try this:

header('Pragma: public');  // required
header('Expires: 0');  // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Cache-Control: private', false);
header('Content-Type: application/pdf');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filepath)) . ' GMT');
header('Content-disposition: attachment; filename=' . $pathinfo['filename'] . '.pdf');
header("Content-Transfer-Encoding:  binary");
header('Content-Length: ' . filesize($filepath)); // provide file size
header('Connection: close');
readfile($filepath);
exit();

这篇关于从php下载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆