One of the things that people ask the most when they are learning to make web pages is how they can put files to be downloaded. I wonder how many of these people are thinking of putting more or less spicy songs, videos or photos to download from their page.
But we have to be clear that the Internet is founded and subsists on the exchange of information. And these downloads are just another form of information exchange. Although from a judicial point of view they are trying to “put doors on the field.” But, well, this is for a post about “mental nonsense on the internet.”
Creating a link to download a file is very simple. The first thing we have to do is upload the file to our server. We can do this in two ways:
- It is good that the server has a system for uploading files from a web page installed. In this case it will be as simple as using a web form.
- Well use an FTP client. This is a program that will be executed on our machine, which is used to connect to a remote system and transfer files from local to this system. They are very simple to use. For example you can download FTP clients from Softonic.
Once we have uploaded our file to the server we must build the page HTML to download it. To download it we will simply have to create a link to the file.
Links are created using the A and using the href attribute. In this attribute we must put the name of the file we want to download. Thus, if our file is called lineadecodigo.txt we will have to put the following line of code:
<a href="lineadecodigo.txt">Download file lineadecodigo.txt</a>
In this code we must be especially careful with the path in which we have uploaded the file. Thus, it is usually not good to upload it to the root directory. So it is advisable to create a download file. In this case, the line of code would look like this:
<a href="/descargas/lineadecodigo.txt">Download file lineadecodigo.txt</a>
And what happens when I click on the link? Well, it all depends on the computer and browser where we are running the website. And the browser will interpret the type (knowing the file extension) of the file and see if it has an associated program to open it.
Thus, if we are on a Windows system, it is most likely that the .txt document will be opened by NotePad, the .mp3 by a music player (WinAmp, Windows Media Player,…) and so on by all the extensions configured on your system.
If the browser does not know the file extension, it only indicates that you want to save it locally. The save option always appears, regardless of the extension.
As a good practice, it is recommended that its extension and size be indicated next to the file to be downloaded, in order to facilitate its manipulation for the user who visits our website.
