Support » Plugin: WP Document Revisions » Corrupted files (DocX, xlsx) on download

  • Resolved tcarterfrance

    (@tcarterfrance)


    Hi, PDF files work fine but when we upload docs and xls they are unreadable, even from the admin. To reproduce the problem :
    /wp-admin/post-new.php?post_type=document
    Put a title and upload a test docx
    Save
    Click the page link and open in new tab. The file is downloaded but corrupted.

    However if I check the file on the server in /web/wp-content/uploads/2019/02
    /40ac5718d70b67c518058ba5147d8f09.doc
    the file is ok. It seem the problem is the during the recuperation of the file from the server.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ben Balter

    (@benbalter)

    Are you using the latest version of WordPress?
    Are you using the latest version of the plugin?
    Does the problem occur even when you deactivate all plugins and use the default theme?

    tcarterfrance

    (@tcarterfrance)

    Ben, hi, thanks for your time. To reaply to your questions :

    WordPress : Version 5.1
    WP Document Revisions : Version 3.2.1
    Does the problem occur even when you deactivate all plugins and use the default theme? YES

    I’ve traced the problem to this :
    /web/wp-content/plugins/wp-document-revisions/includes/class-wp-document-revisions.php
    Line 1007 : readfile( $file );

    Apparently at this point a 3 character “BOM” is added to the beginning of the files ouputted.

    See image here : https://cergy-internet.fr/bug_bom.png

    Txt and PDF files are still readable. Office files are not.

    Server details/phpinfo are here : http://cenatho3.encours.fr/siteinfo.php

    Lots of stuff in Google about this but no solution. I’ve tried changing the content-type and code-page (from UTF-8 to Windows) etc but it always outputs the BOM.

    Any idéas welcome. TIA.
    Thomas CARTER, Cergy Internet, France.

    tcarterfrance

    (@tcarterfrance)

    Found it! Oooof! https://codex.wordpress.org/Installing_WordPress

    “5)If your text editor saves as Unicode, make sure it adds no byte order mark (BOM). Most Unicode-enabled text editors do not inform the user whether or not it adds a BOM to files; if so, try using a different text editor.”

    In my case wp-config.php had been saved as UTF-8-BOM instead of just UTF-8. So it was quietly adding a BOM tag to the beginning of the output!

    Hope this helps someone else out there. Ben thanks again for a great plugin.

    Matt

    (@etchells27)

    I am having this same problem with MS Excel files being corrupted.
    I don’t think the stated resolution applies???
    Latest WP version 5.1.1
    latest plugin version 3.2.1
    MacOS with Safari.
    I typically edit using the CPanel built-in code edit function which is set to UTF-8 by default. Not sure if BOM encoding is there or not.

    The 2 Excel (.xlsx) files on my website server open fine in Excel. These were uploaded to the website server using the plugin. I can open them directly from my computer over the internet (FTP).

    If I now download these files using the plugin, they will not open in Excel (Excel does not recognize the file structure).

    When I click on a document title in the list (the shortcode list), it tries to open the file in a new tab, as if it is a post.

    When I download the file, it gets an .html extension added to the filename. Why is that?

    Maybe a cache problem???

    • This reply was modified 9 months, 2 weeks ago by Matt.
    Matt

    (@etchells27)

    Other related issues:

    If the document is password protected, it will not download (with Safari?). I think the download is waiting for the password to be entered. But no request or window is generated for the user to be able to enter a password. Eventually the download loses connection with the server. If I make the file public, it downloads, but with an added .html extension appended to the filename.

    I see on the internet some references to Safari adding .html extensions to downloads. I do not yet understand what is going on with this.

    However, even if I make the document public, then download it, then remove the .html extension, Excel cannot read the resulting file.

    So, possibly several issues here, or maybe all tied together.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Corrupted files (DocX, xlsx) on download’ is closed to new replies.