功能描述:上傳圖片檔案到指定目錄後,在本檔案根據URL傳入的檔案名稱加上檔案所在目錄根據檔案完整路徑。再將該檔案二進位資料流寫入服務頁面,達到隱藏圖片真實位址防止外部引用圖片的效果。
以下是引用片段:
< %@LANGUAGE="VBSCRIPT " CODEPAGE="936"%>
<%
Option Explicit
Const SysUrl=" http://www.80Boby.com/uImg/ "
Function ReadBinFile(fileName)
Dim objStream,bin
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile fileName
bin = objStream.Read
objStream.Close
ReadBinFile = bin
End Function
Function isSelfRefer()
Dim sHttp_Referer, sServer_Name
sServer_Name = CStr(Request.ServerVariables("HTTP_REFERER"))
if instr(sServer_Name,"80boby.com")<>0 或 instr(sServer_Name,"freeat63.cn")<>0 then
IsSelfRefer = True
Else
IsSelfRefer = False
End If
End Function
if request.QueryString("Mark")="getPic" then
Dim RealUrl,fso
Dim uFileName:uFileName=Request.QueryString("x")
RealUrl=Server.MapPath("檔案真實路徑"&uFileName)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if Not(fso.FileExists(RealUrl)) then RealUrl=Server.MapPath("logo.gif")
if Not(isSelfRefer) then
RealUrl=Server.MapPath("logo.gif")
end if
response.contenttype = "image/jpeg"
response.BinaryWrite ReadBinFile(RealUrl)
response.end
end if
%>