时间:2021-07-01 10:21:17 帮助过:35人阅读
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);;
}
为了方便,我写了一个函数forceDownload(),然后通过调用该函数即可。