【问题标题】:PHP - Opening uploaded DOCX files with the correct MIME TYPEPHP - 使用正确的 MIME 类型打开上传的 DOCX 文件
【发布时间】:2011-01-17 17:38:30
【问题描述】:

我有用户上传我提供下载的 DOCX 文件。我们遇到的问题是 DOCX 文件的未知 mime 类型导致 IE 将这些文档作为 Zip 文件打开。

它在 Windows/IIS 服务器上运行。

因为这是共享主机,我无法更改任何服务器设置。

我在想我可以写一些处理 DOCX 文件的代码,也许是自定义输出:

if (extension=docx) {

header("Content-Disposition: attachment; etc)
header('Content-Type: application/application/vnd.openxmlformats-officedocument.wordprocessingml.document');

//Output the file contents etc

}

这是一个可行的解决方案吗?如果是这样,有人可以帮助填补空白吗?

(PS我知道上面的语法不正确,只是一个简单的例子)

【问题讨论】:

    标签: php zip mime docx


    【解决方案1】:

    应该这样做:

    header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
    header('Content-Disposition: attachment; filename="myfile.docx"');
    readfile('myfile.docx');
    

    【讨论】:

      【解决方案2】:

      是的,这会很好。 PHP 文档基本上有你想要的exact code

      【讨论】:

        猜你喜欢
        • 2012-10-09
        • 2016-04-25
        • 2011-05-11
        相关资源
        最近更新 更多