ASP文件下载用流输出的函数

来源:互联网 发布:js里getjson 编辑:程序博客网 时间:2024/05/21 18:32

ASP文件下载用流输出的函数和方法

asp中关于流的用法大家都已经很熟悉了,今天大学堂站长发布一个文件下载用asp流输出的方法,写成asp函数,代码如下:

<%
' 下载文件
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
%>

此代码经过大学堂站长测试,可以正常使用,特写成函数的形式,方便大家调用!

本文位置:大学堂>>程序设计>ASP文件下载用流输出的函数
标签:aspAsp源码程序设计
分类:程序设计| 发布:大学堂| 查看:3 | 发表时间:2011-6-16
原创文章如转载,请注明:转载自大学堂 http://www.dxtcc.com/
本文链接:http://www.dxtcc.com/program/156.html

原创粉丝点击