Download PDF Instead of Loading into the browser

Download PDF I’ll bet a cookie you’ve seen those instructions on downloading PDF (ebooks) like “Please click this link with the right mouse-button, then select the “Save Target As…” option from the popup menu and save the file in your PC”.
 But why to force your customers to make extra actions if you exactly want they download your PDF?!
Also what to do with all those links inside email messages?..
I would like to set up a download page on my domain in order to give away a free ebook on generating traffic.
I want to use a link to allow users to DOWNLOAD PDF files. But when I set it up the PDF file gets directly loaded into the browser. Is there something I can do to ensure that when people click on the link on a page or in an E-mail message that the PDF file gets immediately downloaded to their disk and not loaded in their browser?

This article describes 2 ways to let them download PDFs by just clicking a link.

.htaccess trick is the simplest way

If your hosting allows you to use .htaccess files, add this directives into the .htaccess at the folder with your PDF-files:

<Files *.pdf>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
  Header set Content-Transfer-Encoding binary

This prevents loading the pdf’s into the browser.

php-script to force downloading

In case you are not able to use .htaccess files, take this download.php script and upload this script onto your site in the folder with PDF-files.

Now use this script with your pdf-links like below:
download.php?name=eBook.pdf instead of eBook.pdf
 instead of


by Michel Komarov, © Copyright 2007.


Share in social bookmarking:These icons link to social bookmarking sites where readers can share and discover new web pages.  digg BlinkList Reddit NewsVine YahooMyWeb co.mments

3 Responses to “Download PDF Instead of Loading into the browser”

  1. Richard Says:

    Hi Michel

    would this work for .mp3 also with the following adjustments?

    ForceType application/octet-stream
    Header set Content-Disposition attachment
    Header set Content-Transfer-Encoding binary

    download.php?name= talk.mp3 instead of talk.mp3

    thanks in Advance

  2. michel Says:

    Hi Richard,

    Yes, you can use this solution for files of any type.
    For .mp3

    <Files *.mp3>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
    Header set Content-Transfer-Encoding binary

    You’ll need to adjust the download.php script to work with .mp3
    Open it with a test-editor, find the line:
    if ($name && preg_match("/\.pdf$/i",$name) && file_exists($name)) {
    Substitute the pdf with mp3.

    Then use: download.php?name=talk.mp3 instead of talk.mp3


  3. ausis Says:

    cool thanks for that Michel I have been trying to figure this out for my mobile downloads section of my site at ausis.iinfo Free mobile image downloads For YOU…

Got a question?   Leave a Reply

You must be logged in to post a comment.