开发者

PHP - Opening uploaded DOCX files with the correct MIME TYPE

I have users uploading DOCX files which I make available for download. The issues we have been experiencing is the unknown mime types of DOCX files which causes IE to open these docs as Zip files.

It is running on a Windows/IIS server.

Because this is a shared host, I cannot change any server settings.

I was thinking that I could just write some code that would handle DOCX files, perhaps custom output:

if (extension=docx) {

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

//Output the file contents etc

}
开发者_开发技巧

Would this be a viable solution?? If so, can someone help fill in the gaps?

(PS I know the above syntax is not correct, just a quick example)


This should do it:

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


Yes, that will work fine. The PHP docs have basically the exact code you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜