您的位置
主页 > 网站技术 > 语言编程 > » 正文

使用PHP强制下载PDF文件示例

来源: 站长圈 点击:

话不多说,直接上代码。

复制代码 代码如下:

forceDownload("pdfdemo.pdf"); 

function forceDownload($filename) { 

if (false == file_exists($filename)) { 

return false; 

// http headers 

header('Content-Type: application-x/force-download'); 

header('Content-Disposition: attachment; filename="' . basename($filename) .'"'); 

header('Content-length: ' . filesize($filename)); 

// for IE6 

if (false === strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6')) { 

header('Cache-Control: no-cache, must-revalidate'); 

header('Pragma: no-cache'); 

// read file content and output 

return readfile($filename);; 




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明