Download A file

Discussion in 'PHP' started by cancer10, Sep 27, 2006.

  1. #1
    If I want my users to download a .zip or .exe file the command is

    <a href=filename.exe>Download</a>
    or
    <a href=filename.zip>Download</a>

    This will ask the visitors where to save the file on their hard disk.

    But what if I want my users to download a doc/pdf/php/html file and I dnt want the browser to display these on the the browser itself but ask the users to save them.

    <a href=filename.php>Download</a> will simple display the page on the browser.


    PS: I dont wanna compress them.

    Any help appreciated
     
    cancer10, Sep 27, 2006 IP
  2. Evoleto

    Evoleto Well-Known Member

    Messages:
    253
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    In your filename.php file before sending the contents to the visitor, add several header lines that will tell the browser what do to with the content. For example:

    
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="downloaded.pdf"');
    readfile('my_pdf_file.pdf');
    
    PHP:
    A comprehensive list of MIME types to be used in conjunction with the "Content-type" header can be accessed here.
     
    Evoleto, Sep 27, 2006 IP