PHP - 文档数据库 - 在 iOS 上无法在 Safari 中打开

PHP - Document Database - Unable to open in Safari on iOS

我有文件数据库,用户可以通过在线 PHP 驱动网站 search/download。我包含 PDF、.doc、.docx 文件等。到目前为止,在 Mac/Windows.

的桌面上一切正常

我们现在正在 iOS 9 上使用移动版 Safari 测试该站点,当我们单击 link 下载其中一个 .docx 文件时出现奇怪的错误:

Unable to Read Document
An error occurred while reading the document

如果我将文档另存为 .doc 文件并更新数据库,则它会成功下载。在 PHP 页面中,我根据文件扩展名设置 content-header 如下:

if($url == "jpg"){ 
 header('Content-type: image/jpeg'); 
} else if($url == "gif"){ 
 header('Content-type: image/gif'); 
} else if($url == "doc"){ 
 header('Content-type: application/msword');
} else if($url == "dot"){ 
 header('Content-type: application/msword');
} else if($url == "docx"){ 
 header('Content-type: application/msword');
} else if($url == "xls"){ 
 header('Content-type: application/vnd.ms-excel');
} else if($url == "xlsx"){ 
 header('Content-type: application/vnd.ms-excel');
} else if($url == "png"){ 
 header('Content-type: image/png');
} else if($url == "pdf"){ 
 header('Content-type: application/pdf');
} else if($url == "mp3"){ 
 header('Content-type: audio/mpeg');
// set default
} else{ 
 header('Content-type: application/force-download'); 

}

是否有不同的 content-type header 我应该设置或我可以进行一些其他更改以使移动版 Safari 识别它是一个 .docx 文件并像往常一样打开它?

原来我错了 header .docx 文件。它应该设置为:

} else if($url == "docx"){ 
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');