代码:
function downloadFile(){
//文件路径(路径+文件名)
$file_name = U('/temp/downloadfile.xlsx','',false,true);
// required
header('Pragma: public');
//no cache
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
//强制下载
header('Content-Type:application/force-download');
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
//输出到浏览器
readfile($file_name);
exit();
}
代码2:
//文件路径
$filename = U('/temp/downloadfile.xlsx','',false,true);
header("Content-Type:application/force-download");
header("Content-Disposition:attachment;filename=".basename($filename));
readfile($filename);
|
请发表评论