当前位置:Gxlcms > PHP教程 > header-PHP导出EXCEL文件时总是自动打开,请问如何防止?

header-PHP导出EXCEL文件时总是自动打开,请问如何防止?

时间:2021-07-01 10:21:17 帮助过:90人阅读

PHP导出EXCEL文件时总是自动打开,请问如何防止?

    header("Content-Type:   application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$outputFileName");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    $xlsWriter->save("php://output");

回复内容:

PHP导出EXCEL文件时总是自动打开,请问如何防止?

    header("Content-Type:   application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$outputFileName");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    $xlsWriter->save("php://output");

改成

header('Content-Type: application/octet-stream');

人气教程排行