簡體   English   中英

PHP-文檔數據庫-無法在iOS的Safari中打開

[英]PHP - Document Database - Unable to open in Safari on iOS

我有文件數據庫,用戶可以通過在線PHP驅動的網站搜索/下載文件。 我包含PDF,.doc,.docx文件等。到目前為止,在Mac / Windows上的桌面上一切正常。

現在,我們正在使用移動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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM