Problems downloading Excel files with an xlsx extension in WordPress
The skinny: WordPress is appending xls to xlsx causing annoying error messages when a user tries to view those files. I’ve got a fix after the jump. And, unfortunately – for now, at least – it calls for a change to the core code.
My company finally upgraded from Office 2003 to Office 2007 last year and, as a result, have been changing a lot of document file extensions. As a result, I have had lots of problems uploading those files to WordPress. After upload, when a user tries to view/download an xlsx document from Internet Explorer or Firefox, they were given this warning:
The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?
There’s a lot of information on the web about changing the registry on user computers to stop the message from popping up. It’s a mostly harmless, but annoying, message that still allows the user to open the file. However, it’s the type of error that alarms a user and makes them send me emails, and changing everybody’s registry is not a viable option.
Further, it seemed the problem was more likely with WordPress than it was with Excel or my browser or the server because, when attempting to download, I noticed WordPress appended the old “xls” extension to the end of the filename. As in, it read filename.xlsx.xls, which is why Excel thought it was a bogus extension.
I found the cause of the trouble to be in the wp-includes/functions.php file around the 2515 line, so unfortunately it took some core code hacking that I’m not happy about. You’ll notice xslx is listed twice in the allowed mime-type uploads, but the second mention of xlsx is an incorrect mime-type and it’s overriding the first correct mention of it. Remove xlsx from the list of mime-types labeled application/vnd.ms-excel and make sure it’s listed under the mime-type of application/vnd.openxmlformats-officedocument.spreadsheetml. If you’re having this problem, you should see the problem clear up right away without having to re-upload anything.
There’s a thread about this on the WordPress support forums and a bug report on trac, but I’m not sure the change has been committed yet.
One Response to Problems downloading Excel files with an xlsx extension in WordPress
Leave a Reply Cancel reply
About me
I'm a web developer, designer, writer, communications professional, former newspaper journalist, Wordpress evangelist, news junkie, pop culture addict AND MORE! Currently employed as the Technical Communications Specialist at the Seattle Housing Authority.
My Favorite Thing Ever Right Now
Tim Tebow 80 Yard Game Winning Touchdown Pass to Demaryius Thomas - 2011-2012 AFC Wildcard (by TheNFLonDemand)
Latest from Twitter
-
generalgentry Laura GentryHow bougie is it that @carollani and I are going to buy a child's bike trailer for our dog tonight?
-
generalgentry Laura GentryDamn, a 3rd grader was shot at school??
Current Favorites from Twitter
-
michaelianblack Michael Ian BlackSocks. Sometimes they feel good to put on, sometimes they feel good to take off. Crazy shit, man.
-








Hi
I use WordPress on my site too. Thank you for your sharing. I have problem too on my old site.
This is very clear up!