2010-02-17 42 views
2

我有用戶上傳DOCX文件,我可以下載。我們遇到的問題是導致IE將這些文檔作爲Zip文件打開的未知MIME類型的DOCX文件。PHP - 使用正確的MIME類型打開上傳的DOCX文件

它在Windows/IIS服務器上運行。

因爲這是共享主機,所以我無法更改任何服務器設置。

我在想,我可以只寫一些代碼,將處理docx文件,或許自定義輸出:

if (extension=docx) { 

header("Content-Disposition: attachment; etc) 
header('Content-Type: application/application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 

//Output the file contents etc 

} 

這將是一個可行的解決方案?如果是這樣,有人可以幫助填補空白?

(PS我知道上面的語法是不正確的,只是一個簡單的例子)

回答

2

這應做到:

header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 
header('Content-Disposition: attachment; filename="myfile.docx"'); 
readfile('myfile.docx'); 
0

是的,這將正常工作。 PHP文檔基本上有你想要的exact code