You can use streaming download (consuming memory, use less) or go directly to the file.
<%
Const USE_STREAM = 0 '0. Download without stream (Adodb.Stream) 1. Download with stream
Const ALLOW_FILE_EXT = "rar,zip,chm,doc,xls,swf,mp3,gif,jpg,jpeg,png,bmp" 'Allow the extension of the downloaded file to prevent the source code from being downloaded
Dim sDownFilePath 'Download file path
sDownFilePath = Trim(Request("FilePath"))
'Or get the file path from the database based on the passed file ID
' If sDownFilePath is an absolute path, be sure to convert sDownFilePath to a relative path to this file'sDownFilePath
= "focus.swf"
Call DownloadFile(sDownFilePath)
Function DownloadFile(s_DownFilePath )
'Determine whether the file name is passed
If IsNull(s_DownFilePath) = True Or Trim(s_DownFilePath) = "" Then
OutputErr "Error: First determine the file to download, the download failed"
End If
'Determine whether the extension is legal
Dims_FileExt
s_FileExt = Mid(s_DownFilePath, InstrRev(s_DownFilePath, ".")+1)
If InStr("," & ALLOW_FILE_EXT & ",", "," & s_FileExt & ",") <= 0 Then
OutputErr "Error: The file type (" & s_FileExt & ") is not allowed to be downloaded, and the download failed"
End If
s_DownFilePath = Replace(s_DownFilePath, "", "/")
'For security reasons, downloading files is prohibited in some directories and is handled here.
'
'Check whether the server supports fso
Dim o_Fso
On Error Resume Next
Set o_Fso = Server.CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
Err.Clear
OutputErr "Error: The server does not support the fso component and the download failed"
End If
'Get file name, file size
Dims_FileMapPath
Dim o_File, s_FileName, n_FileLength
s_FileMapPath = Server.MapPath(s_DownFilePath)
If (o_Fso.FileExists(s_FileMapPath)) = True Then
Set o_File = o_Fso.GetFile(s_FileMapPath)
s_FileName = o_File.Name
n_FileLength = o_File.Size
o_File.Close
Else
OutputErr "Error: file does not exist, download failed"
End If
Set o_Fso = Nothing
'Determine whether the downloaded file size exceeds the limit
'
'If it is not downloaded by stream, go directly to the file
If USE_STREAM = 0 Then
Response.Redirect sDownFilePath
Response.end
End If
'Detect whether the server supports Adodb.Stream
On Error Resume Next
Set o_Stream = Server.CreateObject("Adodb.Stream")
If Err.Number <> 0 Then
Err.Clear
OutputErr "Error: The server does not support the Adodb.Stream component and the download failed"
End If
o_Stream.Tyep = 1
o_Stream.Open
o_Stream.LoadFromFile s_FileMapPath
Response.Buffer = True
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=" & s_FileName
Response.AddHeader "Content-Length", n_FileLength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite o_Stream.Read
Response.Flush
o_Stream.Close
Set o_Stream = Nothing
End Function
Sub OutputErr(s_ErrMsg)
Response.Write "<font color=red>" & s_ErrMsg & "</font>"
Response.End
End Sub
%>
http://www.cnblogs.com/jiny-z/archive/2006/08/29/489102.html