当前位置: 移动技术网 > IT编程>开发语言>.net > 利用ADODB.Stream使用浏览器下载服务器文件

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

2019年01月02日  | 移动技术网IT编程  | 我要评论

美航母访香港被拒,僵尸勾女,蕾西·班哈德

download.?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 %>


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网