HTML Download Tag - Trix And Life

Post Top Ad

Sponsor

Wednesday, September 19, 2012

HTML Download Tag


When you create a link in a Web page, the Web browsers automatically attempt 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 initiate a download anyway, even without an HTML download tag.
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.
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 write something like this:
(Right click or option-click the link and choose "Save As..." to download this file.)
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. How to Write a Download Link
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. How to Use PHP to Force a File Download
View the original article here

No comments:

Post a Comment

Post Top Ad

-->