Format: download.asp? Filename= the file name to download
Copy Code code as follows:
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