WordPress.org

Ready to get started?Download WordPress

Forums

WP Publication Archive
[resolved] pdf's not readable on download (6 posts)

  1. cody@joasurveys
    Member
    Posted 1 year ago #

    Hi Eric,

    Having some trouble with WP Pub Archive, files download but Adobe gives an error when you try to open them:

    "Adobe Reader could not open file 'xxxxxxx.pdf' because it is either not a supported file type or because the file has been damaged"

    I've tried re-uploading the pdf's and reinstalling WP Publication Archive, any help or advise would be greatly appreciated. Thanks!

    Site: http://joasurveys.com/publications

    http://wordpress.org/extend/plugins/wp-publication-archive/

  2. Eric Mann
    Member
    Plugin Author

    Posted 1 year ago #

    Cody,

    Looking at your site, there's something going wrong with the download. The file that is downloading is not the PDF but is instead an HTML file containing an error:

    Directory has no index file.

    For some reason, an include somewhere either isn't working or your server (I see you're running Nginx) is configured in such a way that streaming the PDF file to the browser through openfile.php is disabled.

  3. cody@joasurveys
    Member
    Posted 1 year ago #

    So I am over my head in all this, but still in the fight. A copy of the download link looks like this:

    http://joasurveys.com/wp-content/plugins/wp-publication-archive/includes/openfile.php?file=http|joasurveys.com/wp-content/uploads/2012/11/tides1.pdf

    If you cut it down to just the file location (joasurveys.com/wp-content/uploads/2012/11/tides1.pdf) it opens the pdf in the browser.

    Here's a cut and paste of the openfile.php, in case anything jumps out at you.

    <?php
    if ( ! isset($_GET['file']) )
    die();

    if ( strpos( $_GET['file'], (isset($_SERVER['HTTPS']) ? 'https|' : 'http|') . $_SERVER['SERVER_NAME'] ) === false )
    die();

    require_once('../lib/class.mimetype.php');
    $mime = new mimetype();

    $fPath = str_replace('http|', 'http://', $_GET['file']);
    $fPath = str_replace('https|', 'https://', $fPath);
    $fType = $mime->getType( $fPath );
    $fName = basename($fPath);

    $origname = preg_replace('/_#_#\d*/','',$fName);

    $fContent = fetch_content( $fPath );

    output_content( $fContent, $origname );

    function fetch_content( $url ) {
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_HEADER, 0 );

    ob_start();

    curl_exec( $ch );
    curl_close( $ch );

    $fContent = ob_get_contents();

    ob_end_clean();

    return $fContent;
    }

    function output_content( $content, $name ) {
    header( "Expires: Wed, 9 Nov 1983 05:00:00 GMT" );
    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
    header( "Content-Disposition: attachment; filename=" . $name );
    header( "Content-type: application/octet-stream" );
    header( "Content-Transfer-Encoding: binary" );

    echo $content;
    }
    ?>

    Thanks for getting back to me!

  4. Eric Mann
    Member
    Plugin Author

    Posted 1 year ago #

    Yeah, I know what openfile.php looks like. My only guess, without seeing how your server is configured, is that your server is choking on the fetch_content() call. This is using cURL behind the scenes, which can sometimes be disabled or hobbled by the server configuration.

    Is there any chance you can check your error logs to see if anything is being reported there?

    But the Nginx error that you're seeing is a common error. If you try to access a directory without specifying a filename, Nginx will look at whatever's defined in the try_files declaration for the server config. Usually this includes index.htm index.html index.php. So some file, somewhere, is trying to read or access a directory without specifying a filename and that directory is lacking one of these three files.

    My guess is that the $_GET variable is being stripped off, so openfile.php is trying to do a cURL call for the directory where it resides (basically doing a cURL GET of ''). But I can't be sure of this without seeing your error logs.

    Ideally, the logs will show exactly what's being requested, by what, and what error is occuring. If you can copy-paste those logs, we should be able to narrow things down.

  5. cody@joasurveys
    Member
    Posted 1 year ago #

    Thanks for the reply's Eric!

    Talked to the server people and they found no problems. No log errors were showing up for pdf downloads.

    Talked to the web design company and they went through and found this:

    "It looks like when the caching plugin (super cache) updated, it broke the JavaScript files concatenation. I removed that caching plugin and added a new one that's less aggressive (quick cache). I also added a rule that prohibits the scripts concatenating, which can break them and cause things that depend on AJAX to break."

    They changed the site so that pdf's are hyper-linked in the wp page editor to open in a new tab, not as slick as wp pub archive but gets the job done.

    Thanks!

  6. Eric Mann
    Member
    Plugin Author

    Posted 1 year ago #

    Hmm ... well, the new version of the plugin (hopefully done before the end of the year) will be dumping the openfile.php method to load files anyway. It's old, slow, and as you've demonstrated, prone to failure for a variety of reasons.

    The new system will allow you to treat each publication as a post - with its own description and meta information. You can still use the shortcode to list archives, or can allow people to navigate through a deeper archive at http://yoursite.com/publications.

    Each publication will have its own link (i.e. http://yoursite.com/publication/whatever-title-you-chose) which will display document details, meta information, and present both view and download links. The download link will force the file to be downloaded (as before). The view link will dynamically stream the resource to the browser, allowing the browser to take over and do whatever it needs to the file - i.e. display on screen, continue as a download, or whatever is the default behavior for that file type.

    If there's anything else you'd like to queue up as a change, feel free to add an issue to my internal roadmap and I'll see what I can do: https://github.com/ericmann/WP-Publication-Archive/issues

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.