• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 13次 | 进入软件测试论坛讨论

领测软件测试网 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 %>  

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网