ASP隐藏文件地址,并在下载时替换文件名
时间:2011-03-07 来源:moretop
set rs=server.createobject("adodb.recordset") '创建记录集对象
sql="select top 1 * from files where F_id="&Fileid 'SQL查询语句
rs.open sql,conn,1,1 '打开记录集
if rs.recordcount<1 then
Response.Write "找不到此文件"
else
FileName=rs("F_DocURL")
DownName=rs("F_title")&Mid(FileName, InStrRev(FileName, "."))
' 下面是不希望下载的文件
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=" & DownName
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath("Attachment/"+FileName) '设置路径
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
End if
rs.close '关闭记录集
Set rs=Nothing '释放记录集
conn.close '关闭数据库连接
Set conn=Nothing '释放数据库连接
%>