HTTP response header file Impact file download

Source: Internet
Author: User
Tags header

The Web site contains more than just web pages, and sometimes you need to provide files that users can download. Putting your files on the server and attaching links to the pages is just the first step, and you also need to be aware that the HTTP response headers affect file downloads.

Tip One: Force the download and control the file name

Providing a download link in HTML is simple:

<ahref="http://download.httpwatch.com/httpwatch.exe">Download<a>

This works well for binary files that browsers do not know how to render, such as setup and zip files. A dialog box appears that allows the user to store the file locally.

The problem is that if the file renders itself, different browsers behave differently. For example, if you link a plain text file, the browser will open it and will not be prompted to save the download.

You can join the following response header file to force the File Download dialog box to be used.

Content-disposition:attachment; Filename=<file name.ext>

The head can also control the default file name, which can help you easily generate content like getfile.aspx, but you want to provide a more meaningful filename to the user.

For static content, you can manually configure additional header files on your Web server. For example, the following is set up in IIS:

For dynamically generated content, you need to add this header to the server-side code of the Web page.

After adding the head, the browser always prompts the user to download the file:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.