1. Computing

Discuss in my forum

What is the HTML Download Tag?

How to Set Up File Downloads

By

download button

A download button Image courtesy arinas74 from Stock.xchng

When you click on a link in a web page, your web browser automatically attempts to open that link in the browser window. And now, with various plugins and other features, browsers can open more and more files that they used to be forced to download. Most of the time, this is what we want—after all, we're building web pages. But sometimes you post files to your website that you want people to download to their hard drive rather than view in the browser window.

An HTML download tag seems like the perfect solution. Unfortunately, there is no such thing as an HTML download tag. In order to set up file downloads, you link to the files in the same way you would link to a file to open in the browser window. But there are some ways to force a download anyway, even without a specific tag.

Tell Your Readers About Their Browser Functionality

Every modern browser has what is called a context menu that appears when the right mouse button is clicked (or option plus the mouse button for one-button Macs). When you right click a link one of the options on the context menu is a "Save As..." or "Save link as...". When you choose that, the file on the other side of the link is downloaded to the hard drive, even if it can be opened in the browser. This works even with HTML documents.

The simplest way to emulate an HTML download tag is to simply tell people to right-click on the link to download the file. I typically write something like this:

(Right click or option-click the link and choose "Save As..." to download this file.)

Compress the File to Download

If you want the file to download automatically, then you can use your operating system to compress the file and turn it into a ZIP file. This type of file will download automatically. Here's an article that can help: How to Write a Download Link

Trick the Browser with PHP

Finally, if you know some PHP, you can use a simple 5-line PHP script to force the web browser to download the file without zipping it or asking your readers to do anything. This method relies on HTTP headers to tell the browser that the file is an attachment rather than a web document. Here's an article that explains how to do that: How to Use PHP to Force a File Download

There Isn't an HTML Download Tag, But Now You Don't Need One

It is possible to create a download link that includes features like password protecting the files, count the number of downloads, and other features valuable to file downloads. An HTML tag would not have all the features that everyone wants, so it's better that we use the tools we have. And that gives you a better looking and functioning website.

©2014 About.com. All rights reserved.