Jump to content

how to... click hyperlink to download a PDF file


jasonc

Recommended Posts

well, its not html but here is one answer, my php is not too good, but this looks pretty easy

 

<?php
// 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');
?>

 

http://php.net/manual/en/function.header.php#AEN123154

well, its not html but here is one answer, my php is not too good, but this looks pretty easy

 

<?php
// 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');
?>

 

http://php.net/manual/en/function.header.php#AEN123154

 

well, its not html but here is one answer, my php is not too good, but this looks pretty easy

 

<?php
// 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');
?>

 

http://php.net/manual/en/function.header.php#AEN123154

 

out of the other option showning in other replies i opted for this one seems easy enough.

 

this is the begining of my file that shows the link that is to be clicked to get the download to start.

 

<?php
if (isset($_GET['a'])) {
$articledate = stripstring($_GET['a']);
$filename = "agendas/RRA - " . substr($articledate, 0, 2) . "-" . substr($articledate, 2, 2) . "-" . substr($articledate, 4, 4) . " - Agenda.pdf";

} elseif (isset($_GET['m'])) {
$articledate = stripstring($_GET['m']);
$filename = "minutes/RRA - " . substr($articledate, 0, 2) . "-" . substr($articledate, 2, 2) . "-" . substr($articledate, 4, 4) . " - Minutes.pdf";
}

if ($_GET['d'] == "1" && (isset($_GET['a']) || isset($_GET['m'])) ) {
// outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="<?=$filename;?>"');

// The PDF source is in original.pdf
readfile('<?=$filename;?>');
}
?>

 

i have placed the code given in the start of my file but it seems to have the visitor download the webpage '.../index.php'  itself and not the PDF

ok apart from a slight eror in my code being...

header(Content-Disposition: attachment; filename="<?=$filename;?>"');
// The PDF source is in original.pdf
readfile('<?=$filename;?>');

should be

 

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="'.$filename.'"');

// The PDF source is in original.pdf
readfile("'".$uploaddir.$filename."'");

 

the following happens...

 

in IE the page should all ok with the PDf imbeded in the page in the left hand side of my two table set.

and the download link shows and when clicked i get a download box to download my web page file in view not the PDF file.

 

in FireFox the reverse happens, the PDF does not show in the table (the PDF is open in a PDF viewer, acrobat) and the download box shows the correct file to be downloaded being the actual PDF file.

 

 

i realy do not understand why this happens, anyone got any ideas ?

ok i have tried and tried to get this to work and still not working the same in both FireFox and Internet Explorer.

 

in IE the page should all ok with the PDf imbeded in the page in the left hand side of my two table set.

and the download link shows and when clicked i get a download box to download my web page file in view not the PDF file.

 

in FireFox the reverse happens, the PDF does not show in the table (the PDF is open in a PDF viewer, acrobat) and the download box shows the correct file to be downloaded being the actual PDF file.

 

 

here is the page that i am working from...

 

 

www dot rra dot realistic (takeout space) hostings dot com

 

can anyone see why i have both browsers doing different things.

 

IE is doing what i want to have happen in both if i can.  it alows you to click the download link to get the download box to the correct file the PDF file.

 

but FF seems to open the PDF in its own PDF viewer acrobat, how can i get the file to forcely open in the tables.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.