2015-10-16 29 views
0

我有用戶可以通過在線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文件,並像通常那樣打開它?

回答

0

我發現一個.docx文件的標頭錯誤。它應該設置爲:

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