If we know the actual path of a static file, for example, success! How can I prevent the downloader from obtaining the actual path when downloading 51windows.pdf on the website! This article describes how to use ASP to hide the actual download path of an object.
When we manage website files, we can place files with the same extension in the same directory and create a special name. For example, we can save the following code 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.
<%
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" 'requires logon!
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 file name! "
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; filename =" & 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
%>
From: http://goaler.xicp.net/ShowLog.asp? Id = 512