欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用ADODB.Stream使用浏览器下载服务器文件
分享到: 更多 (0)

相关推荐

  • 暂无文章