PHP实现文件下载:header


代码:

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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM