以下另存为:download.htm
<a href=download.asp?filename=download.asp>guid.asp</a>
以下另存为:download.asp
<%@language=vbscript%>
<%
const forreading=1
const tristatetrue=-1
const file_transfer_size=16384
response.buffer = true
function transferfile(path, mimetype, filename)
dim objfilesystem, objfile, objstream
dim char
dim sent
send=0
transferfile = true
set objfilesystem = server.createobject("scripting.filesystemobject")
set objfile = objfilesystem.getfile(path)
set objstream = objfile.openastextstream(forreading, tristatetrue)
response.addheader "content-type", mimetype
response.addheader "content-disposition","attachment;filename=" & filename
response.addheader "content-length", objfile.size
do while not objstream.atendofstream
char = objstream.read(1)
response.binarywrite(char)
sent = sent + 1
if (sent mod file_transfer_size) = 0 then
response.flush
if not response.isclientconnected then
transferfile = false
exit do
end if
end if
loop
response.flush
if not response.isclientconnected then transferfile = false
objstream.close
set objstream = nothing
set objfilesystem = nothing
end function
dim path, mimetype, sucess,downfilename
downfilename=request("filename")
path = server.mappath(downfilename)
mimetype="text/plain"
sucess = transferfile(path, mimetype,downfilename)
response.end
%>