PDA

View Full Version : link to download pdf



wiklendt
06-22-2005, 01:20 PM
hi,

just wondering if there was a way to force a "save file?" dialog to come up after clicking a link to a pdf (like when downloading exe's) instead of the pdf simply being opened in the browser window?

cheers,
wiklendt.

mwinter
06-22-2005, 01:45 PM
just wondering if there was a way to force a "save file?" dialog to come up after clicking a link to a pdfYou can try by sending two response headers, but it's not guaranteed to work.

First, set the Content-Type header to application/octet-stream. That in itself should make most user agents download rather than show as that MIME type presents binary data, rather than something useful. Unfortunately, Microsoft seem to have a different interpretation of things than most, and will attempt to 'sniff' the real content type (this is the cause of some of its security vulnerabilities, I think).

Secondly, set the Content-Disposition header to attachment; filename="filename.pdf". This unofficial HTTP extension is quite widely implemented and suggests that the content is meant for download with the suggested file name. Once again, Microsoft[1] spoil this somewhat by providing broken support in several versions prior to IE6.

You can make these changes in your server configuration (or a .htaccess file, and similar), or in a server-side script. If you don't have these options available to you, then you can't do anything and it will be up to users to download the files themselves through their browser controls.

Mike


[1] I'm sure other browsers have broken this sort of feature, but I know that Microsoft have consistently.