Forum Moderators: coopster

Message Too Old, No Replies

A little bit of PHP knowledge needed

A little bit of PHP knowledge needed

         

nextnet

12:12 pm on Sep 10, 2011 (gmt 0)

10+ Year Member



Hi,

Here's my issue.. This shouldn't be difficult for someone who knows PHP.. I know only a little bit of it so a solution for this would be appreciated..

On a folder on my server there are pdf files and an index.php page.. Names of pdf files are for example:

2000abcd0001.pdf
2000abcd0002.pdf
etc..

On the index.php file I have a small form e.g.


<form action="" method="post">
<input type="text" name="mypdf_code">
<input type="submit" name="submit_form" value="Download pdf" />
</form>



What I want is when I enter a name of a pdf file in the input box and hit the submit button, to download the respected pdf file.. e.g.

If I enter 2000abcd0002 on the form and hit the button to download the 2000abcd0002.pdf file..

Thanks for taking the time to solve this..

Sincerely,

henry0

10:07 pm on Sep 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is something that could help you.
This will generate a download window to open a PDF
<<<

$attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/dir/dir2/pdf/whatever.pdf";
$filename='filename="whatever.pdf"';

// the two above hard coded location and file name could be var passed as needed. (POST, GET for example)

function pdfDload($attachment_location, $filename)
{
// get attachment location
if (file_exists($attachment_location)) {
// attachment exists

// send open/save pdf dialog to user
header('Cache-Control: public'); // needed for i.e.
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; $filename');
readfile($attachment_location);
die(); // stop execution of further script because we are only outputting the pdf

} else {
die('Error: File not found.');
}
}
pdfDload($attachment_location, $filename);

>>>>