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

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

WBOY
Release: 2016-06-06 20:43:21
Original
1105 people have browsed it

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>
Copy after login
Copy after login

回复内容:

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>
Copy after login
Copy after login

改成

<code>header('Content-Type: application/octet-stream');
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template