Use AdoDb.Stream anti-theft chain

xiaoxiao2021-03-19  203

<% @ Language = "vbscript" CodePage = "936"%>

<%

'*****************************

'File Name Use URL Parameters / Table Single Pass, Item Name is filename, direct output of pictures such as GIF and JPG, other files will pop up the download prompt box

'Example:

' Download File

'*****************************

ON Error ResMe next

Response.buffer = TRUE

Response.clear

Const filedir = "" "Changes in your files in your file

Function getFilePath (filename, filedir) 'Prevents the chain, when the domain name and the domain name of the source address and the domain name of the current file address are output custom error pictures Nosteal.gif

DIM Server_v1, Server_V2

Server_v1 = cstr (Request.ServerVariables ("http_referer")))

Server_v2 = cstr (Request.ServerVariables ("Server_Name"))

IF (Server_V1 <> "" and MID (Server_v1,8, len (server_v2)) = Server_v2) THEN

Getfilepath = filedir & filename

Else

GetFilePath = "Nosteal.gif"

END IF

END FUNCTION

Function getContentType (filename)

Select Case Lcase (Right (FileName, 4))

Case ".asf"

GetContentType = "Video / X-MS-ASF"

Case ".avi"

GetContentType = "Video / Avi"

Case ".doc"

GetContentType = "Application / Msword"

Case ".zip"

GetContentType = "Application / Zip"

Case ".xls"

GetContentType = "Application / VND.MS-Excel"

Case ".jpg", "JPEG", ". GIF", "PNG", ". BMP"

GetContentType = "image / *"

Case ".wav"

GetContentType = "Audio / WAV"

Case ".mp3"

GetContentType = "AUDIO / MPEG3"

Case ".mpg", "MPEG"

GetContentType = "video / mpeg"

Case ".rtf" getContentType = "Application / RTF"

Case ".htm", "html"

GetContentType = "Text / HTML"

Case ".txt"

GetContentType = "text / plain"

Case Else

GetContentType = "Application / Oct-stream"

End SELECT

END FUNCTION

SUB USESTREAM (FilePathString, FileNameString)

DIM FileStream, File, FileContentType, Isattachment

Set filestream = Server.createObject ("adodb.stream")

FileStream.open

FILESTREAM.TYPE = 1

FILESTREAM.LOADFROMFILE (server.mappath (filepathstring))

FILECONTENTTYPE = getContentType (filenameString)

IF (FileContentType <> "image / *") THEN

Isattachment = "attachment;"

Else

Isattachment = ""

END IF

Response.addheader "Content-Disposition", isattachment & "FileName =" & FileNameString

Response.addheader "Content-Length", FileStream.size

Response.Charset = "UTF-8"

Response.contenttype = filecontenttype

Response.binarywrite filestream.read

Response.flush

FileStream.close

Set filestream = Nothing

End Sub

DIM FileName, FilePath

Filename = Trim (Request.QueryString ("FileName"))

FilePath = getfilepath (filename, filedir)

USSTREAM FILEPATH, FILENAME

Err.Number <> 0).

Err.clear

Server.execute ("noimg.gif")

END IF

%>

转载请注明原文地址:https://www.9cbs.com/read-130161.html

New Post(0)