Just save the file below as Download.asp, and then transfer the file to be downloaded as needed. Format: Download.asp?FileName=The name of the file to be downloaded
Copy the 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 file name.
Response.End
End if
'The following are files that you do not want to download
FileExt = Mid(FileName, InStrRev(FileName, .) + 1)
Select Case UCase(FileExt)
Case ASP, ASA, ASPX, ASAX, MDB
Response.Write is a protected file and cannot be downloaded.
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