ASP隐藏真实文件的下载功能实现代码
程序员文章站
2022-05-28 16:05:39
格式: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
复制代码 代码如下:
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
下一篇: ASP 无限级分类实现