<%@ LANGUAGE="VBSCRIPT" %> <% '======================= 'Define the names of your functions '======================= Dim Stream Dim Contents Dim FileName Dim FileExt Const adTypeBinary = 1 '======================= 'Get the actual file name from the URL that is passed to the browser '======================= FileName = request.querystring("file") 'Get the name from the URL 'sName = request.querystring("newname") '======================= 'GIVE AN ERROR MESSAGE IF THE URL IS EMPTY '======================= if FileName = "" Then response.write "Filename Not specified." response.end end if '======================= 'prevent access to certain files '======================= FileExt = Mid(FileName, InStrRev(FileName, ".") + 1) select case UCase(FileExt) Case "ASP", "ASA", "ASPX", "ASAX", "MDB" response.write "You cannot access these file types." response.end end select '======================= 'Start the download process if all is good '======================= response.clear response.Buffer = false Server.ScriptTimeout = 30000 response.contentType = "application/octet-stream" response.addheader "content-disposition", "attachment; filename=" & FileName set stream = server.CreateObject("ADODB.Stream") stream.type = adTypeBinary stream.open 'Response.Write(Server.MapPath("/test/test.asp")) stream.LoadFromFile Server.MapPath("" & FileName) chunk = 2048 iSz = stream.Size response.AddHeader "Content-Length", iSz For i = 1 To iSz \ chunk If Not response.IsClientConnected Then Exit For response.BinaryWrite stream.Read(chunk) Next If iSz Mod chunk > 0 Then If response.IsClientConnected Then response.BinaryWrite stream.Read(iSz Mod chunk) End If End If 'while not stream.EOS' 'response.BinaryWrite Stream.Read 'wend' stream.Close Set stream = Nothing response.Flush response.End %>