Anti-Leech protection principles:
The actual URLs on the server are not directly provided. The files to be accessed are placed in inaccessible directories on the server, therefore, the file to be accessed must be read through asp and sent as a binary stream. If the source address and user logon status are added, leeching can be prevented in a certain sense.
Disadvantage: However, the overhead is also high.
The following are two example functions without permission judgment.
Sub downloadFile (strFile)
On error resume next
Server. ScriptTimeOut = 999999
Dim S, fso, f, intFilelength, strFilename, DownFileName
StrFilename = Server. MapPath (strFile)
Response. Clear
Set s = Server. CreateObject ("ADODB. Stream ")
S. Open
S. Type = 1
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
If Not fso. FileExists (strFilename) Then
'Response. Write ("The specified file cannot be found ")
Showimg "images/logos.gif"
Exit Sub
End If
Set f = fso. GetFile (strFilename)
IntFilelength = f. size
S. LoadFromFile (strFilename)
If err Then
'Response. Write ("Showimg "images/logos.gif"
Response. End
End If
Set fso = Nothing
Dim Data
Data = s. Read
S. Close
Set s = Nothing
If Response. IsClientConnected Then
Response. AddHeader "Content-Disposition", "attachment; filename =" & strFile
Response. AddHeader "Content-Length", intFilelength
Response. CharSet = "UTF-8"
Response. ContentType = "application/octet-stream"
Response. BinaryWrite Data
Response. Flush
End If
End Sub
Showimg (supported by the Persits. Jpeg component)
Sub showimg (FileName)
Response. Clear
Dim Jpeg, temp_pic
On Error Resume Next
Set Jpeg = Server. CreateObject ("Persits. Jpeg ")
If-2147221005 = Err then
'Response. write "does not have this component. Please install it! "'Check whether the AspJpeg component is installed
DownloadFile FileName
Exit Sub
End If
Jpeg. Open (Server. MapPath (FileName) 'Open the image
If err. number then
'Response. write "failed to open the image. Please check the path! "
Jpeg. Open (Server. MapPath ("images/logos.gif "))
Response. end
End if
Temp_pic = Jpeg. Binary
Response. ContentType = "image /*"
Response. AddHeader "Content-Disposition", "filename =" & arr_FileName (FileName)
Response. BinaryWrite temp_pic
Response. End
End Sub