Archived topic
External File Link has extension removed
4 replies · Started by Tim on April 7, 2020
Hello
When using a "URL" type ACF field to point to an external .pdf file "Publication Link", when clicking on the link the file extension is removed, landing on a parent page.
<figure class="publication-header-media">
<?php
$cover = get_field('cover');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
$book_link = ( get_field('link') );
if( $cover ) {
echo '<a href="' . $book_link .'">' . wp_get_attachment_image( $cover, $size ) . '</a>';
}
?>
</figure>
I suppose this is a server redirect.
If I enter the URL directly into the browser address bar, the pdf loads in the pdf viewer.
Is there a way I can force the file to download / load in the pdf viewer ?
Hi there,
include target="_blank" attribute in your <a> - this will open a new tab which should open the PDF.
Hmm
target="_blank" is now in there, but no joy.
I think its a CORs issue:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
The browser is protecting the User by not allowing links from a different resource to be opened directly.
I thought CORS was for inline/on_page content, not for opening an outbound address.
As a test I uploaded one of the pdfs to a different domain I manage. The link to that file opened as expected. So I don't think the browser is protecting the visitor for this scenario.
I suppose the target problem server is employing a redirect against "link leaches" or something.