设为首页
加入收藏
繁體中文
首 页客家风情客家影音山歌在线客家商城聊天室留言墙测字算命下载中心IT 技术客家论坛
您当前的位置:天南地北客家人 -> IT 技术-> ASP -> 正文 退出登录 用户管理
栏目导航
· ASP · JSP
· 网络安全 · NET专区
· XML专区 · PHP专区
热门文章
· ASP+JavaScript的完整的..
· [图文] 防范非法用户的侵..
· ASP从数据库中获取文件..
· 网络管理中的常用命令
· [图文] FSO组件操作实例..
· [图文] 千年虫二世诞生业..
· 网络常见木马的手工清除..
· [图文] 简单购物车教程
· 一个ASP(VBScript)简..
· 利用ASP远程获取内容
· 网络常见木马的手工清除..
· asp常用数据库连接方法..
相关文章
· [ASP]利用 xmlhttp 分块..
· 用正则解析图片地址,并利..
· 利用 WSH 作定时工作流程..
· 利用FSO取得BMP,JPG,P..
· asp中利用数组实现数据库..
· 利用static实现表格的颜..
· 关于Win2K3中利用ASP上传..
· 利用sql的存储过程实现d..
· 利用C#线程机制实现应用..
· 一个驱动webcam的类,利..
· 利用XMLSerializer将对象..
· 在ASP.Net中两种利用CSS..
· 利用ASP.NET实现分页管理..
· C/C++中利用空指针简化代..
· ASP.NET中利用存储过程实..
利用ADODB.Stream使用浏览器下载服务器文件
作者:佚名  来源:动网  发布时间:2008-4-16 11:32:55  发布人:Admin

减小字体 增大字体

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


[] [返回上一页] [打 印] [收 藏]
下一篇文章:用asp执行DTC
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
关于本站 - 网站合作 - 免责声明 - 友情连接 - 网站地图 - 客家论坛
本站部份内容来自网络 如无意中侵犯了您的权利 请及时与我们联系 我们会尽快处理
Copyright © 2006-2012   天南地北客家人
Email:hakka360@sina.com   客家人QQ群:33754730
粤ICP备07019796号