How To Create a Download Link

Write Links That Download Files Rather than Display Them

Download progress bar
SpiffyJ/E+/Getty Images

Years ago, when a visitor to your website clicked a link that pointed to a non-HTML document like a PDF file, an MP3 music file, or even an image, those files would download to that person's computer. Today, that is not the case for many common file types.

Instead of forcing a download on these files, today's web browsers simply display them inline, directly in the browser viewport. PDF files will be displayed in the browsers, as will images.

MP3 files will be played directly in the browser window rather than saved as a download file. In many cases, this behavior may be perfectly fine. In fact, it may be preferable to a user having to download the file and then find it on their machine in order to open it. Other times, however, you may actually want a file to be downloaded rather than displayed by the browser.

The most common solution most web designers take when they try to force a file to download rather than be displayed by the browser is to add explanatory text next to the link suggesting that the customer use their browser options to right-click or ctrl-click and choose “Save File...” to download the link. This is really not the best solution. Yes, it works, but since many people don’t see those messages, this isn’t a very effective approach and it can result in some annoyed customers.

Instead of forcing customers to follow specific directions that may not be intuitive to them, this tutorial will show you how you can set up both the above method, and ask your readers to request the download.

It will also show you a trick for creating files that will be downloaded by nearly all web browsers, but that can still be used on the customer’s computer.

Difficulty: Average

Time Required: 10 minutes

What You Need:

  • The file to be downloaded.
  • A web hosting provider

Here’s How It's Done:

Get Your Customers to Do It

  1. Upload the file you want your customers to download to your web server. Make sure you know where it is by testing the full URL in your browser. If you have the correct URL the file should open in the browser window.
    /documents/large_document.pdf
  1. Edit the page where you want the link and add a standard anchor link to the document.
    <a href="/documents/large_document.pdf">Download the large document</a>
  2. Add text next to the link telling your readers they need to right-click or ctrl-click the link in order to download it.
    Right-click (control-click on a Mac) the link and choose “Save Link As...” to save the document to your computer

Change the File to a Zip File

If your readers ignore the instructions to right-click or ctrl-click, you can adjust the file to something that will be automatically downloaded by most browsers, as opposed to that PDF which is read inline by the browser. A zip file or other compressed file type is a good option to use for this method.

  1. Use your operating system compression program to turn your download file into a zip file. How to Zip Files On a Mac Zip Files on Windows
  2. Upload the zip file to your web server. Make sure you know where it is by testing the full URL in your browser window.
    /documents/large_document.zip
  3. Edit the page where you want the link and add a standard anchor link to the zip file.
    <a href="/documents/large_document.zip">Download the large document</a>

Tips:

  • Most operating systems have some compression software built in. If yours doesn’t, you can look up “zip files” in a search engine to find a program to build them for you.
  • You can use this technique for images, movies, music, and documents as well as PDF files. Anything you can compress as a zip file you can post to your site for download.
  • You can also compress multiple files into one zip file, to let your customers download a bunch of files with one click.
  • If none of the above methods appeals you can also force a download with PHP.

Original article by Jennifer Krynin. Edited by Jeremy Girard on 1/5/17.

Format
mla apa chicago
Your Citation
Kyrnin, Jennifer. "How To Create a Download Link." ThoughtCo, Jan. 5, 2017, thoughtco.com/how-to-create-download-link-3466525. Kyrnin, Jennifer. (2017, January 5). How To Create a Download Link. Retrieved from https://www.thoughtco.com/how-to-create-download-link-3466525 Kyrnin, Jennifer. "How To Create a Download Link." ThoughtCo. https://www.thoughtco.com/how-to-create-download-link-3466525 (accessed December 14, 2017).