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

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

WBOY
WBOY原創
2016-06-06 20:43:211087瀏覽

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