Hello,
I have an anchor (<a>) to a PDF file.
Is there any way that when the user clicks the link the file is saved
instead of opened by the browser?
You have to serve it with a MIME type other than "application/pdf". I
think "application/octet-stream" is the one to use, e.g.:
<?php
header('Content-type: application/octet-stream');
readfile('original.pdf');
?>
You should also be able, if all browser vendors could read
spesifications, to use Content-Disposition:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
In php it would be something like "Example #1 Download dialog",
http://us.php.net/en/header:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
These things have to be done on a http-server like Apache or in a
server side script like PHP.
I don't know, but I think Chrome might show pdf files even if there is
no pdf readers installed on the computer. In that case I think some
users might get lost if you only offer them to "open/download" pdf
files. You might want to have two links. One regular link to the pdf
file, and one "open/download" link. Then the user can choose if you
want to view the file in the browser or in a real pdf reader.
You might get a better answer in a web server or server side script
group.