Html Create Download Link File

How to write HTML link code. The code will create this link: Text Link. HTML link to same page. HTML mailto link. HTML link to file download.

  1. Create A File Download Link
  2. Create Html Link To Folder
  3. How To Create Html Links
Note

This document is for Webmasters who want .PDF, .DOC, or another file link to open in a specific way on their web page, not for changing file settings in your Internet browser.

In some situations, developers want to create a web page with links to an Adobe Acrobat .PDF, Microsoft Word .DOC, Microsoft Excel .XLS, or external program files. In these cases, they may want the browser to prompt the user to download the file instead of opening it in the browser window or an external program. There are a few different methods you use to achieve this effect.

Html create download link

Save / Save As option

Create a link to download the file on the web page using the <A HREF> HTML tag. Then, recommend to the web page viewer that they right-click the link and choose the option to Save or Save as the file. Viewers can then download and save the file to their computer.

Zip the file

Compress the file and create a .ZIP file or another compressed file format. Then, create a link to download the file on the web page using the <A HREF> HTML tag. By compressing the file into a ZIP file and creating a link to it, a web browser is unable to directly open the ZIP file. Instead, it will prompt the user to download the ZIP file or automatically download the ZIP file.

For example, the below HTML link would allow a web page viewer to download a file named example.zip, containing the file you compressed to create the ZIP file.

<a href='https://www.computerhope.com/example.zip'>

PHP scripting

Create the below PHP file that can be used to open .PDF files. It can also be modified to allow for the downloading of .DOC or other files.

  1. Create a new file named download.php
  2. After creating the file, copy and paste the below code into the PHP file.
  1. Save the file and upload to the server hosting the web page.
  2. Once uploaded, links to download a PDF file need to point to download.php?file=example.pdf, where example.pdf is the name of the PDF file you want users to download.

Below is an example of a full link using the PHP scripting.

Additional information

  • See the PDF definition for further information about PDF files, questions and answers, and related links.
  • HTML Tutorial
  • HTML References
  • HTML Resources
  • Selected Reading

A webpage can contain various links that take you directly to other pages and even specific parts of a given page. These links are known as hyperlinks.

Hyperlinks allow visitors to navigate between Web sites by clicking on words, phrases, and images. Thus you can create hyperlinks using text or images available on a webpage.

Note − I recommend you to go through a short tutorial on Understanding URL

File

Linking Documents

A link is specified using HTML tag <a>. This tag is called anchor tag and anything between the opening <a> tag and the closing </a> tag becomes part of the link and a user can click that part to reach to the linked document. Following is the simple syntax to use <a> tag.

Example

Let's try following example which links http://www.tutorialspoint.com at your page −

This will produce the following result, where you can click on the link generated to reach to the home page of Tutorials Point (in this example).

The target Attribute

We have used target attribute in our previous example. This attribute is used to specify the location where linked document is opened. Following are the possible options −

Sr.NoOption & Description
1

_blank

Opens the linked document in a new window or tab.

2

_self

Opens the linked document in the same frame.

3

_parent

Opens the linked document in the parent frame.

4

_top

Opens the linked document in the full body of the window.

5

targetframe

Opens the linked document in a named targetframe.

Create

Example

Try following example to understand basic difference in few options given for target attribute.

This will produce the following result, where you can click on different links to understand the difference between various options given for target attribute.

Use of Base Path

When you link HTML documents related to the same website, it is not required to give a complete URL for every link. You can get rid of it if you use <base> tag in your HTML document header. This tag is used to give a base path for all the links. So your browser will concatenate given relative path to this base path and will make a complete URL.

Example

Following example makes use of <base> tag to specify base URL and later we can use relative path to all the links instead of giving complete URL for every link.

This will produce the following result, where you can click on the link generated HTML Tutorial to reach to the HTML tutorial.

Now given URL <a href = '/html/index.htm' is being considered as <ahref = 'http://www.tutorialspoint.com/html/index.htm'

Linking to a Page Section

You can create a link to a particular section of a given webpage by using name attribute. This is a two-step process.

Note − The name attribute deprecated in HTML5. Do not use this attribute. Use id and title attribute instead.

First create a link to the place where you want to reach with-in a webpage and name it using <a...> tag as follows −

Second step is to create a hyperlink to link the document and place where you want to reach −

This will produce following link, where you can click on the link generated Go to the Top to reach to the top of the HTML Text Link tutorial.

Setting Link Colors

You can set colors of your links, active links and visited links using link, alink and vlink attributes of <body> tag.

Example

Save the following in test.htm and open it in any web browser to see how link, alink and vlink attributes work.

This will produce the following result. Just check color of the link before clicking on it, next check its color when you activate it and when the link has been visited.

Download Links

You can create text link to make your PDF, or DOC or ZIP files downloadable. This is very simple; you just need to give complete URL of the downloadable file as follows −

This will produce following link and will be used to download a file.

File Download Dialog Box

Sometimes it is desired that you want to give an option where a user will click a link and it will pop up a 'File Download' box to the user instead of displaying actual content. This is very easy and can be achieved using an HTTP header in your HTTP response.

For example, if you want make a Filename file downloadable from a given link then its syntax will be as follows.

Note − For more detail on PERL CGI programs, go through tutorial PERL and CGI.