Anchor. Open file. Is this possible?

S

shapper

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?

Thanks,
Miguel
 
A

Ari Heino

shapper kirjoitti seuraavasti:
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?

Thanks,
Miguel

Ultimately, no. It depends from eg. the user's configuration. This issue
was covered not long ago.
The user can always right-click it and save (or you can advice to do so).
 
S

Sherm Pendley

shapper said:
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?

Sure - just right-click and choose "save as."

sherm--
 
S

shapper

Ultimately, no. It depends from eg. the user's configuration. This issue
was covered not long ago.

Yes, that was what I thought ... Just wanted to confirm.
The user can always right-click it and save (or you can advice to do so).

Yes, I know. I will add the advice. Thanks for the tip.

Cheers,
Miguel
 
R

richard

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?

Thanks,
Miguel


Is that so you can download a virus along with it?
You're not gonna tell me I must download it. No way.
 
R

Roy A.

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.
 
J

Jonathan N. Little

shapper wrote:
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?

Why do you care? From the perspective of your server

"load in browser" == download

It is difficult to "force" anything on a use, but your can encourage
download where the link uses a server-side script to set HTTP headers to
content-disposition: attachment
 
A

Adrienne Boswell

Gazing into my crystal ball I observed shapper <[email protected]>
writing in

Yes, that was what I thought ... Just wanted to confirm.


Yes, I know. I will add the advice. Thanks for the tip.

And I would add to include the size of the file as well. For a very
small PDF I might let my browser open it, but for a long technical
manual sort of thing, I would probably want to save it somewhere and
read it at my leisure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top