Category: developers journal

Internet Explorer saves Office 2007 files as .zip downloaded from Apache web server

Author: seven May 12, 2009

This falls into category – If It Weren’t So Sad It Would Be Funny. Well the other day, I was making dynamic pricelist generator for elkotech.hr webshop. User logs in, generates Excel (.xlsx) pricelist with his own discounts and stuff and downloads it. Except for slow Excel 2007 worksheet creation with php code, everything is pretty straight forward.

After I deployed the stuff on production server, clients calls me up and says – “Hey, what kind of zip file did you create? It’s full of strange xml files!”. Doh! What zip? Scratch…Scratch… What browser do you use? Aha.. Internet Explorer. :)

The thing is – since Apache doesn’t come out of the box with mime handlers for “new” Office 2007 formats (.docx, .xslx …), he sends that .xlsx file as Content-Type: text/plain. Internet Explorer (6,7,8) tries to be smart and figures out that .xlsx is nothing more than zip file containing lots of xml files, and therfor offers user to save that document as .zip file. Rendering my beautiful pricelist useless in the process.

The workaround is simple – just add this to your .htaccess file (or appropriate Apache config file to which you have access)
AddType application/vnd.openxmlformats .docx .pptx .xlsx
After that, files with those extensions will be served with correct content type – Content-Type: application/vnd.openxmlformats.

Alternatively, you could deliver the files on your own trough php’s fpassthru and add appropriate heders by your self, but fpassthru is slow as hell.

screenshot-elko-crop

Author
seven
CEO/CTO at Nivas®
Neven Jacmenović has been passionately involved with computers since late 80s, the age of Atari and Commodore Amiga. As one of internet industry pioneers in Croatia, since 90s, he has been involved in making of many award winning, innovative and successful online projects. He is an experienced full stack web developer, analyst and system engineer. In his spare time, Neven is transforming retro-futuristic passion into various golang, Adobe Flash and JavaScript/WebGL projects.

    Leave a Reply

    Your email address will not be published. Required fields are marked *