【问题标题】:Firefox : Open XLSX file not saving file butn opening binaryFirefox:打开 XLSX 文件不保存文件但打开二进制文件
【发布时间】:2009-09-24 16:22:04
【问题描述】:

我生成了一个文件服务器端,我希望客户端自动打开它:它是一个 XLSX 文件。 Firefox 只是打开文件,我在浏览器中看到 XLSX 文件的二进制内容,但我希望它通过另存为...框打开。

它在 Chrome 中使用相同的代码运行良好(它会保存它)但不是 firefox...

有什么想法吗?

【问题讨论】:

    标签: php javascript excel firefox


    【解决方案1】:

    Have a look at this - Php exec and return binary

    您是否发送了正确的标头? 像

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"yourfile.xlsx\"");
    

    更新

    header('Content-Type: application/xls');
    header('Content-Disposition: attachment; filename=example.xlsx');
    header('Pragma: no-cache');
    echo file_get_contents("/path/to/yourfile.xlsx");
    

    更新 2

    电子表格 mime 类型

    application/vnd.ms-excel [official]
    application/msexcel
    application/x-msexcel
    application/x-ms-excel
    application/vnd.ms-excel
    application/x-excel
    application/x-dos_ms_excel
    application/xls
    

    更新 3

    关于您的 javascript 问题,您是否尝试过使用

    location.href instead of window.open ??
    

    【讨论】:

    • 该文件已经生成...我希望用户能够打开该文件,该文件将弹出“另存为”对话框。但是当我用 window.open 打开 XLSX 文件的 URL 时,它会在浏览器中显示文件的实际二进制文件。
    【解决方案2】:

    您需要确保将此 mime 类型作为 Content-Type 标头发送:-

    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    所以你需要将 .xslx 扩展名映射到服务器上的这种 mime 类型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-02
      • 1970-01-01
      • 2020-07-21
      • 2018-06-02
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多