各位老师,帮帮我把这段代码做一下修改,小弟实在是不会了。
这段代码原本是文件下载的防盗链代码,我想把它改成隐藏网页真实地址的代码。这段代码是用来下载文件的,我不想下载,想在当前页面打开指定的页面。请问各位高手,该如何修改?我试了好多次,都不行。。
<%
From_url = Cstr(Request.ServerVariables( "HTTP_REFERER "))
Serv_url = Cstr(Request.ServerVariables( "SERVER_NAME "))
if mid(From_url,8,len(Serv_url)) <> Serv_url then
response.write "非法链接! " '防止盗链
response.end
end if
if Request.Cookies( "Logined ")= " " then
response.redirect "/login.asp " '需要登陆!
end if
Function GetFileName(longname) '/folder1/folder2/file.asp=> file.asp
while instr(longname, "/ ")
longname = right(longname,len(longname)-1)
wend
GetFileName = longname
End Function
Dim Stream
Dim Contents
Dim FileName
Dim TrueFileName
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
if lcase(right(FileName,3))= "gif " or lcase(right(FileName,3))= "jpg " or lcase(right(FileName,3))= "png " then
Response.ContentType = "image/* " '对图像文件不出现下载对话框
else
Response.ContentType = "application/ms-download "
end if
Response.AddHeader "content-disposition ", "attachment; filename= " & GetFileName(Request.QueryString( "FileName "))
Set Stream = server.CreateObject( "ADODB.Stream ")
Stream.Type = adTypeBinary
Stream.Open
if lcase(right(FileName,3))= "htm " then '设置htm类型文件目录
TrueFileName = "/the_pdf_file_s/ "&FileName
end if
Stream.LoadFromFile Server.MapPath(TrueFileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
------解决方案--------------------去掉
Response.ContentType = "application/ms-download "
Response.AddHeader "content-disposition ", "attachment; filename= " & GetFileName