Recently one of our clients reported that some visitors were having problems downloading Office 2007 (Word, Excel and Powerpoint) files that they had uploaded via their Wordpress CMS, that we had implemented for them. The problems they reported were that some visitors, who were using Internet Explorer were downloading docx, xlsx and pptx files and their computers were opening them as though they were zip files.
My first thoughts upon hearing this problem is that there was some kind of Wordpress issue and how it handled file uploads. Wordpress is blogging platform and a content management system and might not have been equipped to deal with these kinds of document types correctly yet. Well, at least not on Internet Explorer. A few searches around the web and more specifically the wordpress support forums really did not throw much light on the situation, which lead me to believe the problem lay elsewhere.
Knowing that the problem only affected Internet Explorer, I assumed that the problem could not be related to anything other than this browser as no others were affected. However, a lot of frantic googling later, I discovered that what was happening was basically as follows:
- The web server (in this case, Apache) serves the file without the correct Mimetype
- The browser downloads the file and then different browsers handle the files in different ways.
In the case of browsers such Firefox, Safari and Chrome, the file is handed off to the correct application dictated by the file extension, so in this case the files are opened correctly with Office 2007 (presuming the computer has been setup with the correct filetype associations). I am not sure of the security implications of opening something by relying on just the file extension to dictate the type of file it is, I will leave that matter for someone more intelligent and informed than myself to debate.
However, in the case of Internet Explorer, due to the absence of a mimetype supplied by the server, it appears to look at the file contents for the type of file it is. So why is it opening it as a zip file in that case? Well, from what I can gather the new file formats introduced with Office 2007 are based on zip files that contain all the necessary resources for that document, so Internet Explorer is seeing it as a zip file and sending it to whichever program you have installed that is associated with Zip files.
So how do we fix this issue and make Internet Explorer handle the files correctly? We need to explicitly tell the server to serve the files with the correct mimetype, in the case of Apache, we can do this by adding certain rules to the .htaccess file at the root of your server.
The following rules should be added near the beginning of your file and they tell the server what mimetypes to associate with each file extension. Once you have added these and uploaded the file, Internet Explorer should download the files correctly.
AddType application/vnd.ms-word.document.macroEnabled.12 .docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
Related posts:




