download.asp?file=相对路径的文件
就可以把这个文件下载下来
<%
call downloadFile(replace(replace(Request("file"),"\",""),"/",""))
Function downloadFile(strFile)
6 ' make sure you are on the latest MDAC version for this to work
7 ' -------------------------------------------------------------
8
9
0 ' get full path of specified file
strFilename = server.MapPath(strFile)
' clear the buffer
Response.Buffer = True
6 Response.Clear
7
8 ' create stream
9 Set s = Server.CreateObject("ADODB.Stream")
0 s.Open
' Set as binary
s.Type =
' load in the file
6 on error resume next
7
8
9 ' check the file exists
0 Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h>Error:</h>" & strFilename & " does not exist<p>")
Response.End
end if
6
7 ' get length of file
8 Set f = fso.GetFile(strFilename)
9 intFilelength = f.size
0
s.LoadFromFile(strFilename)
if err then
Response.Write("<h>Error: </h>" & err.Description & "<p>")
Response.End
6 end if
7
8 ' send the headers to the users browser
9 Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
0 Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite s.Read
6 Response.Flush
7
8
9 ' tidy up
60 s.Close
6 Set s = Nothing
6
6
6 End Function
6
66 %>








