利用ADODB.Stream使用浏览器下载服务器文件

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

download.asp?file=相对路径的文件

就可以把这个文件下载下来

<%

call downloadFile(replace(replace(Request("file"),"\",""),"/",""))

Function downloadFile(strFile)

' make sure you are on the latest MDAC version for this to work

' -------------------------------------------------------------

' get full path of specified file

strFilename = server.MapPath(strFile)

' clear the buffer

Response.Buffer = True

Response.Clear

' create stream

Set s = Server.CreateObject("ADODB.Stream")

s.Open

' Set as binary

s.Type = 1

' load in the file

on error resume next

' check the file exists

Set fso = Server.CreateObject("Scripting.FileSystemObject")

if not fso.FileExists(strFilename) then

Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")

Response.End

end if

' get length of file

Set f = fso.GetFile(strFilename)

intFilelength = f.size

s.LoadFromFile(strFilename)

if err then

Response.Write("<h1>Error: </h1>" & err.Description & "<p>")

Response.End

end if

' send the headers to the users browser

Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name

Response.AddHeader "Content-Length", intFilelength

Response.CharSet = "UTF-8"

Response.ContentType = "application/octet-stream"

' output the file to the browser

Response.BinaryWrite s.Read

Response.Flush

' tidy up

s.Close

Set s = Nothing

End Function

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航