PDA

View Full Version : Please Help Create Download Link.



Cheng
10-28-2006, 01:22 PM
Hi.

I asked here before if it is possible to create a download link for a PDF file that opens if clicked the download without displaying the PDF file in the IE browser window and I've been told that it is not possible.
Now I found this website and here it is possible.
Please check out the PDF download link below the text content.

Example Website (http://www2.mercedes-benz.co.uk/content/unitedkingdom/mpc/mpc_unitedkingdom_website/en/home_mpc/passenger_cars/home/products/new_cars/SL-Class_Roadster_2006/prices.html)

As I understand it there is used javascript but I'm not sure.
Can someone tell me how this is done?

Thanks in advance.

ItsMeOnly
10-28-2006, 01:38 PM
Well, basically the trick is server-side, because of "content-disposition" directive in server response. No javascript in there.

If you have access to php or CGI scripts, you can add a wrapper that sends required header:

In apache you can create .htaccess file with content like this:


Action downloader /cgi-bin/wrapme.php
<Directory /path/to/files>
AddHandler downloader .pdf
</Directory>


while the wrapme.php (in this case, a php written wrapper) is:


<?php
$file = $_SERVER['PATH_TRANSLATED'];
if (file_exists($file)) {
header('Content-type: application/pdf');
header('Content-transfer-encoding: binary');
header('Content-disposition: filename=' . basename($file));
header('Content-length: ' . filesize($file));
readfile("$file");
} else {
header("HTTP/1.0 404 Not found");
}
?>

Twey
10-28-2006, 04:50 PM
That's not perfect, though. It all depends on the user's browser settings.

ItsMeOnly
10-28-2006, 06:08 PM
Actually, at least speaking from experience with NN4, Mozilla, Firefox, IEs, Opera and HotJava (tried them all, luck of having several computers-some with very old browsers)- this works, unless of course you mean when user selected "helper application" to open the filetype, and made it a default.

You can always try pulling it as application/octet-stream too :)

Cheng
10-29-2006, 07:00 AM
Hi ItsMeOnly.
Hi Twey.

Thanks for all your replies.
If I use this:
In apache you can create .htaccess file with content like this:

Action downloader /cgi-bin/wrapme.php
<Directory /path/to/files>
AddHandler downloader .pdf
</Directory> Is this mean that I have to place the PDF file in the cgi-bin folder?
And where I want the link to appear I have to add the code and the path like in this example:
Action downloader /cgi-bin/wrapme.php
<Directory /http://www.mysite.com/cgi-bin/file.pdf>
AddHandler downloader .pdf
</Directory>Did I enter the path correct or does it needs to be entered differently?
Is there anything else I have to do to make it work?
I want it to work for IE as regarding to the site stats 99% of the site visitors are IE users.

Thanks again for your help.

Twey
10-29-2006, 12:48 PM
Is this mean that I have to place the PDF file in the cgi-bin folder?No, you'd have to place it in /path/to/files. Obviously you can modify this.
Did I enter the path correct or does it needs to be entered differently?It should be a local path to a directory (hence <Directory>). Things starting with a protocol (http://, for example) are URLs, not paths, and should not begin with a slash (in fact, I don't think it is permissible to put URLs in this field, although I could be wrong).
Action downloader /cgi-bin/wrapme.phpNote that this should point to the wrapme.php file provided above.