When we manage website files, we can put files with the same extension under the same directory and create a special name, for example, put the PDF file directory as the_polic_file_s.CodeSave it as "down. asp". Its online path is http://www.xx.com/down.asp. we can use http://www.xx.com/down.asp? Filenameapps51windows.pdf to download this file, and the downloader cannot see the actual download path of this file! In down. asp, you can also set whether to log on to the downloaded file to determine whether the downloaded Source Page is an external website, so as to prevent the file from being leeched.[Source: feitec.com content, reprinted, please specify the source]
Sample Code:[Source: feitec.com content, reprinted, please specify the source]
<%
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 "illegal link! "'Preventing leeching
response. end
end if
If request. cookies ("logined") = "" Then
response. redirect "/login. ASP "'login required!
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 "invalid/Webpage/asp/041101/24 .htm! "
Response. End
End if
Fileext = mid (filename, limit Rev (filename, ".") + 1)
Select case ucase (fileext)
Case "asp", "asa", "aspx", "asax", "mdb"
Response. Write "illegal operation! "
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/*" 'does not display the download dialog box for the image file.
Else
Response. contenttype = "application/MS-download"
End if
Response. addheader "content-disposition", "attachment; 200497141230.htm=" & getfilename (request. querystring ("FILENAME "))
Set stream = server. Createobject ("ADODB. Stream ")
Stream. type = adtypebinary
Stream. Open
If lcase (right (filename, 3) = "pdf" then' sets the PDF file directory
Truefilename = "/the_polic_file_s/" & filename
End if
If lcase (right (filename, 3) = "Doc" then' sets the doc-type file directory
Truefilename = "/my_d_o_c_file/" & filename
End if
If lcase (right (filename, 3) = "GIF" or lcase (right (filename, 3) = "jpg" or lcase (right (filename, 3 )) = "PNG" then
Truefilename = "/all_images _/" & filename 'set the image file directory
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
%>