PHP - 文档数据库 - 无法在iOS上的Safari中打开
问题描述:
我有用户可以通过在线PHP驱动的网站搜索/下载的文件数据库。我包含PDF,.doc,.docx文件等。到目前为止,在Mac/Windows上的桌面上,一切正常。PHP - 文档数据库 - 无法在iOS上的Safari中打开
我们现在正与移动Safari浏览器测试在iOS 9的网站,当我们点击链接下载的.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');