Default to download PDF files and so on instead of opening in the browser

Source: Internet
Author: User
Tags end root directory
Browser | download | browser | download <%
Dim Stream
Dim Contents
Dim FileName
Dim Fileext
Const adTypeBinary = 1
filename = request.querystring ("filename")
If FileName = "" Then
Response.Write "Invalid filename."
Response.End
End If
' Below is a file that you don't want to download
Fileext = Mid (filename, InStrRev (filename, ".") + 1)
Select case UCase (Fileext)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
Response.Write "protected file, cannot download."
Response.End
End Select
' Download this file
Response.Clear
Response.ContentType = "Application/octet-stream"
Response.AddHeader "Content-disposition", "attachment"; Filename= "& FileName
Set Stream = server. CreateObject ("ADODB.") Stream ")
Stream.type = adTypeBinary
Stream.open
Stream.loadfromfile Server.MapPath (FileName)
While not Stream.eos
Response.BinaryWrite Stream.read (1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
Use: Download.asp? Filename=/files/my.doc
Put your doc file in the root directory files and you can put it somewhere else.

Such as:
<a href= "download.asp? Filename=/files/my.doc "> Click to download Word document </A>




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.