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 if 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:

  1. The web server (in this case, Apache) serves the file without the correct Mimetype
  2. 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/ .docm 

AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx 

AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx 

AddType application/ potm 

AddType application/vnd.openxmlformats-officedocument.presentationml.template potx 

AddType application/ ppam 

AddType application/ ppsm 

AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx 

AddType application/ pptm 

AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx 

AddType application/ xlam 

AddType application/ xlsb 

AddType application/ xlsm 

AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx 

AddType application/ xltm 

AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx

You may also like

Why does Revium use WordPress?

WordPress is one of the most popular and widely-used CMS’s available and is popular for a reason – it’s an easy to use, powerful CMS tool and it’s free. With the huge range of plugins & widgets to choose from, WordPress becomes whatever you need it to be.

Keep Reading

The art of 4 dimensional database design

A web application is only as good as the architecture behind it and a large part of that will be the database design and schema. Good data structures can mean the difference between your system being scaleable and robust or your system being covered in a whole heap of metaphorical band aids within a few years.

Keep Reading

Newsletter sign up

Every couple of months we send out an update on what's been happening around our office and the web. Sign up and see what you think. And of course, we never spam.