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

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 tigerlgf 的 blog

download.asp?file=相对路径的文件
就可以把这个文件下载下来

<% 
 
call downloadfile(replace(replace(request("file"),"\",""),"/","")) 
 
function downloadfile(strfile) 
' make sure you are on the latest mdac version for this to work 
' ------------------------------------------------------------- 
 
 
' get full path of specified file 
strfilename = server.mappath(strfile) 
 
 
' clear the buffer 
response.buffer = true 
response.clear 
 
' create stream 
set s = server.createobject("adodb.stream") 
s.open 
 
' set as binary 
s.type = 1 
 
' load in the file 
on error resume next 
 
 
' check the file exists 
set fso = server.createobject("scripting.filesystemobject") 
if not fso.fileexists(strfilename) then 
response.write("<h1>error:</h1>" & strfilename & " does not exist<p>") 
response.end 
end if 
 
 
' get length of file 
set f = fso.getfile(strfilename) 
intfilelength = f.size 
 
 
s.loadfromfile(strfilename) 
if err then 
response.write("<h1>error: </h1>" & err.description & "<p>") 
response.end 
end if 
 
' send the headers to the users browser 
response.addheader "content-disposition", "attachment; filename=" & f.name 
response.addheader "content-length", intfilelength 
response.charset = "utf-8" 
response.contenttype = "application/octet-stream" 
 
' output the file to the browser 
response.binarywrite s.read 
response.flush 
 
 
' tidy up 
s.close 
set s = nothing 
 
 
end function 
 
%>

本文关键:利用ADODB.Stream使用浏览器下载服务器文件
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top