欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-18 11:51:57
...
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');
相关标签: php header