¡¡¡¡¿ÉÒÔÓÃÁ÷ÏÂÔØ(ºÄÄڴ棬ÉÙÓÃ)»òÖ±½Óתµ½¸ÃÎļþ.

<%
Const USE_STREAM = 0 '0.²»ÓÃÁ÷(Adodb.Stream)ÏÂÔØ 1.ÓÃÁ÷ÏÂÔØ
Const ALLOW_FILE_EXT = "rar,zip,chm,doc,xls,swf,mp3,gif,jpg,jpeg,png,bmp" 'ÔÊÐíÏÂÔØµÄÎļþµÄÀ©Õ¹Ãû£¬·ÀÖ¹Ô´´úÂë±»ÏÂÔØ
Dim sDownFilePath 'ÏÂÔØÎļþ·¾¶
sDownFilePath = Trim(Request("FilePath"))
'»òÕ߸ù¾Ý´«¹ýÀ´µÄÎļþID´ÓÊý¾Ý¿âÖлñÈ¡Îļþ·¾¶
'Èç¹û sDownFilePath Ϊ¾ø¶Ô·¾¶£¬Ò»¶¨Òª½« sDownFilePath ת»»ÎªÏà¶Ô ±¾ÎļþµÄÏà¶Ô·¾¶
'sDownFilePath = "focus.swf"
Call DownloadFile(sDownFilePath)
Function DownloadFile(s_DownFilePath)
    'ÅжÏÓÐû´«µÝÎļþÃû
    If IsNull(s_DownFilePath) = True Or Trim(s_DownFilePath) = "" Then
        OutputErr "´íÎó£ºÏÈÈ·¶¨ÒªÏÂÔØµÄÎļþ£¬ÏÂÔØÊ§°Ü"
    End If
    'ÅжÏÀ©Õ¹ÃûÊÇ·ñºÏ·¨
    Dim s_FileExt
    s_FileExt = Mid(s_DownFilePath, InstrRev(s_DownFilePath, ".")+1)
    If InStr("," & ALLOW_FILE_EXT & ",", "," & s_FileExt & ",") <= 0 Then
        OutputErr "´íÎó£ºÎļþÀàÐÍ£¨" & s_FileExt & "£©²»ÔÊÐí±»ÏÂÔØ£¬ÏÂÔØÊ§°Ü"
    End If   
    s_DownFilePath = Replace(s_DownFilePath, "/", "/")
    'ΪÁ˰²È«£¬Ä³Ð©Ä¿Â¼½ûÖ¹ÏÂÔØÎļþ£¬ÔÚÕâÀï´¦Àí
    '   
    '¼ì²â·þÎñÆ÷ÊÇ·ñÖ§³Öfso
    Dim o_Fso
    On Error Resume Next
    Set o_Fso = Server.CreateObject("Scripting.FileSystemObject")
    If Err.Number <> 0 Then
        Err.Clear
        OutputErr "´íÎ󣺷þÎñÆ÷²»Ö§³Öfso×é¼þ£¬ÏÂÔØÊ§°Ü"
    End If

    'È¡µÃÎļþÃû£¬Îļþ´óС
    Dim s_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 "´íÎó£ºÎļþ²»´æÔÚ£¬ÏÂÔØÊ§°Ü"
    End If
    Set o_Fso = Nothing
    'ÅжÏÊÇ·ñÏÂÔØµÄÎļþ´óС³¬¹ýÏÞÖÆ
    '       
    'Èç¹û²»ÊÇÓÃÁ÷ÏÂÔØ£¬Ö±½Óתµ½¸ÃÎļþ
    If USE_STREAM = 0 Then
        Response.Redirect sDownFilePath
        Response.end
    End If
    '¼ì²â·þÎñÆ÷ÊÇ·ñÖ§³ÖAdodb.Stream
    On Error Resume Next
    Set o_Stream = Server.CreateObject("Adodb.Stream")
    If Err.Number <> 0 Then
        Err.Clear
        OutputErr "´íÎ󣺷þÎñÆ÷²»Ö§³ÖAdodb.Stream×é¼þ£¬ÏÂÔØÊ§°Ü"
    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
%>