09-20-2011, 11:23 AM
Please i have a website which is created using only HTML AND CSS..
Now i want to add a download button where the user can click and download pdf file . Please i need an idea of how to do that..
If you can help with code , i will be very happy
09-20-2011, 01:20 PM
You can keep your existing HTML/CSS page, but you'll have to add a PHP script to handle the download of the PDF. The script will cause the "OPEN or SAVE" box to appear for the user.
The PHP method will let you serve the PDF file to the user with a different filename.
That means the user won't know what the "real" PDF filename is on your server.
Alternatively, you can just link to the PDF file and it can open in a new window.
<a href="mypdf.pdf" target="_blank">Here is the PDF</a>
Not sure which one you would rather do.
09-20-2011, 04:17 PM
I suggest using mlseim's link, as it'd be better for you to learn with, since your doing html/css. I don't think your ready for PHP if you haven't dealt with it before.
But a way to handle PDF downloads would be something like this.
<a href="pdf_server.php?file=pdffilename">Download my eBook</a>
$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
echo fread($fp, 65536);
flush(); // this is essential for large downloads
09-20-2011, 08:25 PM
He posted in PHP, so I assume he wants the PHP method?
If you want to "hide" the real PDF filename, you have to come up with
a cross-reference to convert a code from the form to a filename (of your PDF).
You don't want to let the user see the "real" PDF filename?
But if that's not an issue, there's the download example that myfayt provided.