频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> asp教程 -> 利用ADODB.Stream使用浏览器下载服务器文件

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

作者:未知  来源:转载  发布时间:2005-9-17 21:12:11  发布人:acx

减小字体 增大字体

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 %>


将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· ASP.NET高级教程(1):ASP..
· 网站生成静态页面,及网..
· 用Socket发送电子邮件(利..
· 用ADO的COMMAND对象实现..
· 信息分散成Web2.0产业软..
· ASP编程入门进阶(十三)..
· 邮件发送测试页面--前台..
· Fireworks三帧打造酷Ban..
· PHP在Linux下连接MSSQLS..
· 淡淡的花3
· 英国消费者青睐网上购物..
· 把NT 4.0下的ASP应用迁移..
· Flash游戏制作:弹力球(..
· HTML教程:收集的常用的H..
· 翻盖再点燃 Fireworks制..
· 用Photoshop绘制SD娃娃(..
相关文章
· 一个利用adsi得到局域网信息..
· 利用adodb.stream直接下载任..
· 利用Adodb.Stream直接下载文..
· 在ASP中利用ADO显示Excel文..
· 利用ADSI对IIS进行编程
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号