开发学院WEB开发ASP ASP使用流输出文件下载 阅读

ASP使用流输出文件下载

 2009-06-30 04:26:00 来源:WEB开发网   
核心提示:<%' 下载文件function downloadfile(fullpath)downloadfile = falsedim strfilename, s, fso, f, intfilelengthset fso = server.createobject("scripting.filesys

<%
' 下载文件
function downloadfile(fullpath)

downloadfile = false

dim strfilename, s, fso, f, intfilelength

set fso = server.createobject("scripting.filesystemobject")

if not fso.fileexists(fullpath) then


exit function

end if

set f = fso.getfile(fullpath)

'获取文件大小

intfilelength = f.size

set s = server.createobject("adodb.stream")

s.open

s.type = 1

s.loadfromfile(fullpath)

response.buffer = true

response.clear

'response.addheader "Content-Encoding","GB2312" ' 乱码的解决方案

'response.addheader "content-type","application/x-msdownload"

response.addheader "content-disposition","attachment;filename=" & f.name

response.addheader "content-length" ,intfilelength

response.contenttype = "application/octet-stream"

while not s.eos


response.binarywrite s.read(1024 * 64)


response.flush

wend

s.close

set s = nothing

downloadfile = true
end function
%>

Tags:ASP 使用 输出

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接