WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Firefox can't open PDF links from WordPress multi-site (16 posts)

  1. ssj_costy
    Member
    Posted 9 months ago #

    Hello,

    I have a WordPress multi-site, and my problem is that Firefox can't open any of the PDFs that I have there. I get a dark-gray screen and it says "This PDF document might not be displayed correctly", but I am able to download it. In .htaccess I have this rewrite rule for files:
    `RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    The thing is that if I write the actual path to the file it opens it in preview just fine. Also, Chrome and IE don't have this problem.

    Best regards

  2. Firefox probably doesn't like how PHP is parsing it.

    Best Option: Just link directly and not via /files/

    Second Best: Stop using /files/ and switch to the uploads folder, though it's not easy.

  3. ssj_costy
    Member
    Posted 9 months ago #

    Isn't there a way to maybe change some WordPress settings so that PHP will parse it differently? Because I can't really change the links at this point.

  4. Rod Whiteley
    Member
    Posted 9 months ago #

    I'd be interested in seeing this for myself. Can you post an actual link that doesn't work?

  5. ssj_costy
    Member
    Posted 9 months ago #

    This doesn't get opened in the browser:
    http://wp.a-h-b.dk/files/2013/05/test_vinkort_2013_sep_dk_www.pdf

    This does:
    http://wp.a-h-b.dk/wp-content/blogs.dir/3/files/2013/05/test_vinkort_2013_sep_dk_www.pdf

    And it is the same file, the only difference is that for the 1st I am using the rewritten URL.

  6. Isn't there a way to maybe change some WordPress settings so that PHP will parse it differently? Because I can't really change the links at this point.

    No, it's not WP it's your browser.

    http://wp.a-h-b.dk/files/2013/05/test_vinkort_2013_sep_dk_www.pdf works for me on Firefox 24 by the way.... Do you have Adobe Acrobat Reader installed?

    And yes you CAN change links. It's called editing the posts :) Use .htaccess to redirect the older ones.

  7. Rod Whiteley
    Member
    Posted 9 months ago #

    The first one is broken for me in Firefox 24 using the "Preview in Firefox" setting, but it works in an external viewer. The second one works both ways.

    The two links send different HTTP response headers. The Accept-Ranges header is missing from the one that fails, and I see that there's discussion of this header and also Content-Disposition in other forums in relation to PDFs, but I haven't delved into the details.

  8. It's weird, I was able to get both to work in FF. Maybe mine's set to be more forgiving to headers?

    Are you getting the black screen? That looks like it goes back a while with Firefox: http://support.mozilla.org/en-US/questions/938583

  9. ssj_costy
    Member
    Posted 9 months ago #

    Well ok, I will do some research on the response headers, maybe I can patch it up somehow. I will post back the solution if I find it.

  10. Rod Whiteley
    Member
    Posted 9 months ago #

    Yes, I get the black screen.

    On downloading both versions, I see that the first one has two linefeeds at the start. It is not a strictly valid PDF file, but evidently some viewers are tolerant of this.

    The second one starts correctly %PDF-1.6 and it has a harmless carriage return and linefeed at the end, making it exactly the same length as the broken one.

    I can reproduce the problem with a different PDF. I linearized it, removed the final CRLF, and added two LFs at the start. The resulting file opens in an external viewer but causes the black screen in Firefox preview.

  11. *sigh* Stupid Firefox.

    Really since WP has dropped ms-files for new installs of WP, I would do this: http://halfelf.org/2012/dumping-ms-files/

    Get rid of using it :/

  12. ssj_costy
    Member
    Posted 9 months ago #

    I wonder why that is, since both urls point to the exact same file.

  13. ssj_costy
    Member
    Posted 9 months ago #

    It's not easy for me to drop "ms-files", because of some issues... The client's hosting plan doesn't allow ftp access to the files created by WordPress for some reason, so it will be really hard to move them. And the other thing is that we already have thousands of files (images and pdfs).

    I'm still searching for some kind of workaround.

  14. Do you have SSH access? WAY faster.

    The options are these:

    1) Change the links to direct links
    2) Get rid of MS files

    I wish I had a better answer, but it's pretty clear that Firefox + your server's handling of PDF via PHP isn't working, and your only OTHER option would be to write a plugin that would detect if a file was a pdf and, if so, insert headers. Which would be very custom work.

  15. ssj_costy
    Member
    Posted 9 months ago #

    I ended up following your advice and got rid of ms-files. Followed the tutorial you mentioned (http://halfelf.org/2012/dumping-ms-files/), spent quite a while making sure I replaced all kinds of filepath strings in the DB and it all ended up working perfectly!

    Thanks a lot for the help guys :)

  16. ssj_costy
    Member
    Posted 9 months ago #

    And I used a File Browser plugin to move the files.

Reply

You must log in to post.

About this Topic