<%
response.buffer=true
取得要下载的文件,如果不为空。就下载
dim url,trueurl
url="下载文件路径和下载文件名"
fname=request("filename")
if fname<>"" then
trueurlurl=server.mappath("/") &url
end if
set objfso=server.createobject("scripting.filesystemobject")
set fn=objfso.getfile(trueurl)
flsize=fn.size
flname=fn.name
set fn=nothing
set objfso=nothing
set objstream=server.createobject("adodb.stream")
objstream.open
objstream.type=1
objstream.loadfromfile url
select case lcase(right(flname,4))
case ".asf"
contenttype="video/x-ms-asf"
case ".avi"
contenttype="video/avi"
case ".doc"
contenttype="application/msword"
case ".zip"
contenttype="application/zip"
case ".xls"
contenttype="application/vnd.ms-excel"
case ".gif"
contenttype="image/gif"
case ".jpg","jpeg"
contenttype="image/jpeg"
case ".wav"
contenttype="audio/wav"
case ".mp3"
contenttype="audio/mpeg3"
case ".mpg", "mpeg"
contenttype="video/mpeg"
case ".rtf"
contenttype="application/rtf"
case ".htm","html"
contenttype="text/html"
case ".txt"
contenttype="text/plain"
case ".asp", ".asa", "aspx", "asax", ".mdb"
response.write "受保护文件,不能下载."
response.end
case else
contenttype="appliation/octet-stream"
end select
response.addheader "content-disposition", "attachment; filename="&flname
response.addheader "content-length", flsize
response.charset="utf-8"
response.contenttype=contenttype
response.binarywrite objstream.read
response.flush
response.clear()
objstream.close
set objstream=nothing
%>