您的位置:首页 > 编程语言 > PHP开发

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

2014-01-17 16:15 681 查看

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);;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息