欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP隐藏真实文件的下载功能实现代码

程序员文章站 2023-01-24 23:46:49
格式:download.asp?filename=要下载的文件名 复制代码 代码如下:dim stream dim contents dim filename dim fi...
格式:download.asp?filename=要下载的文件名
复制代码 代码如下:

dim stream
dim contents
dim filename
dim fileext
const adtypebinary = 1
filename = request.querystring("filename")
if filename = "" then
response.write "无效文件名."
response.end
end if
' 下面是不希望下载的文件
fileext = mid(filename, instrrev(filename, ".") + 1)
select case ucase(fileext)
case "asp", "asa", "aspx", "asax", "mdb"
response.write "受保护文件,不能下载."
response.end
end select
' 下载这个文件
response.clear
response.contenttype = "application/octet-stream"
response.addheader "content-disposition", "attachment; filename=" & filename
set stream = server.createobject("adodb.stream")
stream.type = adtypebinary
stream.open
stream.loadfromfile server.mappath(filename)
while not stream.eos
response.binarywrite stream.read(1024 * 64)
wend
stream.close
set stream = nothing
response.flush
response.end