利用Stream下载文件

时间:2021-12-02 09:56:39

Function dl(f,n)

    On error resume Next

    Set s=CreateObject("Adodb.Stream")

    s.Mode=3

    s.Type=1

    s.Open

    s.Loadformfile(f)

    if Err..Number>0 then

        Response.status="404"

    Else

        Response.ContentType="application/octet-stream"

        Response.AddHeader "Content-Disposition:","attachment;filename=" & n

        Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)

        if Range=" " then

            Response.BinaryWrite(s.Read)

        Else

            s.position=clng(split(Range,"-")(0))

            Response.BinaryWrite(s.Read)

        End If

    End if

    Response.End

 

函数调用实例

call dl(Server.MapPath("text.zip"),"test.zip")