当前位置: 首页 > 图文教程 > 网络编程 > ASP > 利用ADODB.Stream使用浏览器下载服务器文件

ASP
asp下用fso生成js文件的代码
非常好用的asp备份,还原SQL数据库的代码
asp从字符串里截取N个带HTML的字符的函数
asp下Response.Buffer提速
ASP,vbs正则轮翻在文章段落后加上网址等内容
ASP为字符串中的网址自动加上链接
ASP vbs 代码大小写规范
ASP实现智能搜索实现代码
asp结合fso实现文件或文件夹创建删除等操作的函数
asp下对POST提交数据限制的解决方法
asp+Access通用的自动替换数据库中的字符串
asp alexa查询小偷程序
迅雷API接口_通过脚本调用迅雷自动下载资源
asp下的一个检测链接是否正常的函数
asp一句话木马原理分析
asp生成不需要数据库的中奖码
asp遍历目录及子目录的函数
asp数据库连接rs("user.id")
vbs或asp采集文章时网页编码问题
新手asp编程的基本法则与常见错误注意事项

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 71 ::
收藏到网摘: n/a

download.asp?file=相对路径的文件
就可以把这个文件下载下来

<%
2
3 call downloadFile(replace(replace(Request("file"),"\",""),"/",""))
4
5 Function downloadFile(strFile)
6 ' make sure you are on the latest MDAC version for this to work
7 ' -------------------------------------------------------------
8
9
10 ' get full path of specified file
11 strFilename = server.MapPath(strFile)
12
13
14 ' clear the buffer
15 Response.Buffer = True
16 Response.Clear
17
18 ' create stream
19 Set s = Server.CreateObject("ADODB.Stream")
20 s.Open
21
22 ' Set as binary
23 s.Type = 1
24
25 ' load in the file
26 on error resume next
27
28
29 ' check the file exists
30 Set fso = Server.CreateObject("Scripting.FileSystemObject")
31 if not fso.FileExists(strFilename) then
32 Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
33 Response.End
34 end if
35
36
37 ' get length of file
38 Set f = fso.GetFile(strFilename)
39 intFilelength = f.size
40
41
42 s.LoadFromFile(strFilename)
43 if err then
44 Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
45 Response.End
46 end if
47
48 ' send the headers to the users browser
49 Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
50 Response.AddHeader "Content-Length", intFilelength
51 Response.CharSet = "UTF-8"
52 Response.ContentType = "application/octet-stream"
53
54 ' output the file to the browser
55 Response.BinaryWrite s.Read
56 Response.Flush
57
58
59 ' tidy up
60 s.Close
61 Set s = Nothing
62
63
64 End Function
65
66 %>