Computing.Net > Forums > Web Development > download pdf hyperlink

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

download pdf hyperlink

Reply to Message Icon

Name: firefox86
Date: August 14, 2004 at 03:10:22 Pacific
OS: Windows XP
CPU/Ram: 1.80Ghz, 256RAM
Comment:

Hi,
I have a file that is in .pdf format for my website.

If you left click on the link, it will open the Adobe Reader and open the file.

What I want to do is when you left click, it opens a dialogue box that asks you where you want to save the file.

I know you can do this by right clicking and choosing save as, but is there any way by just one simple left click to downlaod it?

Thanks

Mike



Sponsored Link
Ads by Google

Response Number 1
Name: Jamie_McCoy
Date: August 14, 2004 at 07:02:19 Pacific
Reply:

you could put it in a zip folder, that would work

Jaymc.co.nr


0

Response Number 2
Name: FBI Agent
Date: August 14, 2004 at 09:53:35 Pacific
Reply:

im pretty sure there is a way, i just dont know what it is. i saw it a while ago when i was practicing php and looking at www.php.com. it has little tutorials and stuff and it just happened to show a small snippet of what you need to do that.

FBI Agent

AIM: EliteAssassin187


0

Response Number 3
Name: FBI Agent
Date: August 14, 2004 at 09:55:37 Pacific
Reply:

crap, that was php.net lol

FBI Agent

AIM: EliteAssassin187


0

Response Number 4
Name: -Bryan-
Date: August 14, 2004 at 16:08:11 Pacific
Reply:

Create a file called dowload.php containing the following:

<?php
$filename = $_GET['filename'];
if( ! is_file($filename) || $filename[0] == '.' || $filename[0] == '/' )
die("Bad access attempt.\n");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>

When you want to call the file use:
http://www.yourwebsite.com/download.php?filename=acrobatfilename.pdf

That'll bring up the box asking to open, save, etc.

Enjoy!


0

Response Number 5
Name: -Bryan-
Date: August 14, 2004 at 16:11:31 Pacific
Reply:

And forgive my ridiculous spelling errors. =)

The filename at the top should read download.php not dowload.php

Of course, you could name the file whatever you like. That won't have any effect on the script.


0

Related Posts

See More



Response Number 6
Name: Khalid
Date: August 14, 2004 at 23:13:03 Pacific
Reply:

This is a nice way of forcing downloads, but I think with this script people can access all your other scripts aswell; that doesnt seem like a very secure thing...
Perhaps an extra if-then - check is needed to prevent the download-script from sending files you dont want to share...


0

Response Number 7
Name: -Bryan-
Date: August 15, 2004 at 00:00:57 Pacific
Reply:

Hmmmmmm. Good point. Now that I look at it, you're right. And I could have sworn I fixed that. Argh.

I guess you could always hardcode the filename into the php file, i.e. $filename = 'file.pdf' where file.pdf is the actual file name.

Hmmmmm. Let me go back to working on this.


0

Response Number 8
Name: -Bryan-
Date: August 15, 2004 at 14:48:59 Pacific
Reply:

Okay, you could slap this in to limit the file type to pdf or whatever:

$file = explode('.', $filename);
if($file[1] != 'pdf')
die('Could not download selected file.');

or I suppose you could make it so it won't download php scripts:

$file = explode('.', $filename);
if($file[1] = 'php')
die('Could not download selected file.');



0

Response Number 9
Name: firefox86
Date: August 16, 2004 at 05:03:01 Pacific
Reply:

wow.. uumm headache :P i'm a newbie at php scripting lol

i can only do simple email scripts where you fill out a form and click send.

So all I need to do is copy the first script that you sent, and add the last bit that you sent to it.. and save it as .php ?


0

Response Number 10
Name: firefox86
Date: August 16, 2004 at 05:10:58 Pacific
Reply:

aahh yes it worked.. thank you so much!! very very helpful :)


0

Response Number 11
Name: -Bryan-
Date: August 16, 2004 at 13:04:37 Pacific
Reply:

Woo! Good to hear it worked!! And correct, the final script would look like this...just be sure to change where it says pdf to whatever file type you are using:


<?php
$filename = $_GET['filename'];
if( ! is_file($filename) || $filename[0] == '.' || $filename[0] == '/' )
die("Bad access attempt.\n");
$file = explode('.', $filename);
if($file[1] != 'pdf')
die('Could not download selected file.');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>


0

Sponsored Link
Ads by Google
Reply to Message Icon

Dreamweaver Import help Internet Problem: http://...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: download pdf hyperlink

error - php file to download pdf. www.computing.net/answers/webdevel/error-php-file-to-download-pdf/3828.html

PDF file to be Downloaded www.computing.net/answers/webdevel/pdf-file-to-be-downloaded/405.html

Forcing a Save-As box... PDF www.computing.net/answers/webdevel/forcing-a-saveas-box-pdf/367.html