• Some of my posts contain uploaded PDF files. The following script get at first one PDF attachment of a post and the displays a link to download the file:

    <?php
    
    $args = array(
                   'post_type' => 'attachment',
                   'numberposts' => 1,
                   'post_status' => null,
                   'post_parent' => $post->ID,
                   'post_mime_type' => array( 'application/pdf' )
                  );
    
    $attachments = get_posts( $args );
    
    $pdfURL = wp_get_attachment_url( $attachments[0]->ID ); 
    
    ?>
    
    <a href="<?php echo $pdfURL; ?>" class="loadroutepdf_big" target="_blank">Download PDF</a>

    The problem is that when I click the URL, I get a 404.php processed. The problem does not occur, if the link is copypasted from its field in the media manager on the edit post page. Somehow 2 different links? No, they ARE identical, I checked it. Twice at least ,)

    When I copy the link from the media manager and paste it, the PDF opens. Then I select the link in the address bar and click enter — and get the 404. That’s weird…

    This seems to happen only with one certain link. I could simply rename the file and upload it again, but this is an incident and I don’t want any iterations, that’s why I decided to start this topic.

    You can check the issue on personally, here’s the link copied from media manager:

    https://demo.romanreimche.com/questtravel/wp-content/uploads/2012/06/ROVOS-RAIL-ПРЕТОРИЯ-–-КЕЙПТАУН2.pdf

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘File download link gives 404, file exists. Very weird.’ is closed to new replies.