Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Help on how to add download link on a html website

    Hi ,
    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

    Thanks
    Clement Osei

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.


    .

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    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.

    PHP Code:
    <a href="pdf_server.php?file=pdffilename">Download my eBook</a
    PHP Code:
    header("Content-Type: application/octet-stream");

    $file $_GET["file"] .".pdf";
    header("Content-Disposition: attachment; filename=" urlencode($file));   
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Description: File Transfer");            
    header("Content-Length: " filesize($file));
    flush(); // this doesn't really matter.
    $fp fopen($file"r");
    while (!
    feof($fp))
    {
        echo 
    fread($fp65536);
        
    flush(); // this is essential for large downloads

    fclose($fp); 

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •