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