WordPress.org

Forums

.docx files and functions.php (10 posts)

  1. NickDimmock
    Member
    Posted 4 years ago #

    Hi. We were having problems with our WordPress install and .docx files. We'd successfully added the ability to upload these to posts, and everything was working fine until the links were clicked.

    If we chose to open the file directly in Word, we found the .doc suffix was being added to the file, despite .docx already being there - so test.docx would become test.docx.doc.

    This was a cross-browser, cross-machine issue for us. Saving files to disk and then opening them worked fine and .docx files on the server outside of WordPress worked fine.

    We were able to fix this by editing wp-includes/functions.php, which has two entries for .docx files in its MIME types array.

    On line 2489: 'doc|docx' => 'application/msword',

    On line 2498: 'docx|dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml',

    I figured the script was hitting the first match and sending a MIME type that suggested the file was Word 97-2003 (the .docx files were being identified as this prior to opening on my PC), and I knew Apache - which was working - was sending the second type, which the script would presumably never get to.

    We changed line 2489 to 'doc' => 'application/msword', so .docx files only matched the second line, and the links started working.

    I don't know if this warrants a bug report, so I thought I'd bring it up here first to see what people think.

  2. Doodlebee
    Member
    Posted 4 years ago #

    Interesting. I've uploaded .docx files with no problem in WordPress. The behavior you're describing has never happened to me.

    What plugins do you have installed? or maybe your theme? have you tried deactivating all plugins and switching to twentyten to see if you're still having the issue?

  3. NickDimmock
    Member
    Posted 4 years ago #

    Thanks for this. We have tried disabling our theme and plugins with no luck.

    The reason I didn't report it straight off as a bug is I'm not sure if our PC setup here at work is part of the problem, and editing functions.php is simply solving such a local issue that could be fixed some other way outside of WordPress. The application type certainly appears to be the culprit, in as much as editing it solves the problem. But I've no idea at this point what's responsible for adding the .doc suffix to the end - server? Browser? System? Satan?

    The problem happening at the end of the week really isn't helping our efforts to solve it...

  4. Doodlebee
    Member
    Posted 4 years ago #

    This is a local/intranet issue? what server are you running?

    duh - nevermind. I see you say "Apache".

    You say "We'd successfully added the ability to upload these to posts," - how are you uploading them? The media management is how I always do it, and it causes no problems. but did you do something else/use another method to upload the docx files? I just insert them into the post like I do when I add images.

  5. NickDimmock
    Member
    Posted 4 years ago #

    Yeah, it's Apache on OSX, but as the server behaves as expected outside of WP, I don't think that's an issue.

    I wonder now if Word is the problem - if it gets an application type of application/msword it may be deciding that docx is the wrong suffix, adding .doc and then attempting to convert the file - what I didn't add in my original post was that the added suffix is causing Word to throw three error messages about not being able to convert the file before (successfully) showing it. Otherwise it wouldn't really be an issue.

    However, changing the Apache conf to deliver docx files as application/msword doesn't replicate the problem outside of WP. So the only fix remains in the WP config, though it may not actually be a WP issue.

  6. NickDimmock
    Member
    Posted 4 years ago #

    Just saw the upload question - we've used the Flash uploader and the non-Flash one. I don't think the uploading process is the issue because downloading the file to disk and then opening it works fine (the .doc suffix doesn't get added). If we choose to open the file directly, the suffix gets added (this is opening in full Word, not embedding in the browser). If the problem was limited to a single browser I'd put it down to a browser bug, but it's consistent across IE, FF, Chrome and Opera.

    Thanks again for your suggestions.

  7. Doodlebee
    Member
    Posted 4 years ago #

    What version of Word are you using? the .docx extension wasn't available until Office 2007...

  8. NickDimmock
    Member
    Posted 4 years ago #

    2007, which is a tragedy but at least means it ought to be fine with docx files - which it is, outside of WordPress.

    I don't think there are any knock-on effects of the edit we've made, as both doc and docx files are now working as expected, but of course it'd be nice to nail the culprit.

  9. LafayetteNuke
    Member
    Posted 4 years ago #

    We're seeing the same issue on Windows 7. IE 8 throws a .doc on the end of the extension. Firefox retains the .docx but sees the file as Word 98-2003.

    On the Mac, Chrome and Firefox retain the extension, but Safari goes with .doc. The iPad says it doesn't recognize the .docx extension, but you can then load the file in Pages.

    The MIME mismatch theory seems like the best fit. Is there a WordTrac ticket out there for this yet? I did a search but didn't see one.

  10. LafayetteNuke
    Member
    Posted 4 years ago #

    FYI I created a Trac ticket for this issue:
    http://core.trac.wordpress.org/ticket/17117

Topic Closed

This topic has been closed to new replies.

About this Topic