Asp anti-Leech principle and code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.