首页 >后端开发 >php教程 >header - PHP导出EXCEL文件时总是自动打开,请问如何防止?

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

WBOY
WBOY原创
2016-06-06 20:43:211096浏览

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

<code class="lang-php">    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");
</code>

回复内容:

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

<code class="lang-php">    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");
</code>

改成

<code>header('Content-Type: application/octet-stream');
</code>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn