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


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

我有文件数据库,用户可以通过在线PHP驱动的网站搜索/下载。I包含PDF, .doc, .docx文件等。到目前为止,Mac/Windows桌面运行正常。

我们现在正在iOS 9和移动Safari上测试网站,当我们点击链接下载一个。docx文件时,我们得到了一个奇怪的错误:

Unable to Read Document
An error occurred while reading the document

如果我将文档保存为.doc文件并更新数据库,那么它将成功下载。在PHP页面中,我根据文件扩展名设置了内容头,如下所示:

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'); 

}

是否有一个不同的内容类型的头,我应该设置或其他一些改变,我可以让移动Safari识别它是一个。docx文件,并像往常一样打开它?

原来我的.docx文件头是错误的。应该设置为:

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