[分享]ASP图片防盗链代码
来源:
互联网
日期:2009-11-14
<% Const FileType = "gif|jpg|jpeg|bmp" Const FilePath = "./upload" //是图片目录 Qstring= Request("Id") //接收参数 On Error Resume Next Response.Buffer = True Response.Clear Dim Server_v1,Server_v2,Path 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 TFilePath = FilePath & "/" &Qstring //有参数传入时要加栽的图片 Else TFilePath = "upload/nopic.jpg" //这是当出错时要加载的图片 End If If ChkFile(TFilePath) Then Response.Write("<h2>错误提示: </h2>" & err.Description & "") DownloadFile(TFilePath) Function UseStream(FileName) Dim FileStream,File Set FileStream = Server.CreateObject("ADODB.Stream") FileStream.Open FileStream.Type = 1 File = server.MapPath(FileName) FileStream.LoadFromFile(File) 'Response.ContentType = "application/octet-stream" Response.BinaryWrite FileStream.Read Response.Flush FileStream.Close Set FileStream = Nothing End Function Function DownloadFile(FileName) On error resume next Server.ScriptTimeOut=999999 Response.Clear Dim FileType,ADS,StrFileName,Data FileType=Lcase(Split(FileName,".")(ubound(Split(FileName,".")))) StrFileName=Server.Mappath(FileName) TempFileName = Split(StrFileName,"\")(Ubound(Split(StrFileName,"\"))) Set ADS = Server.CreateObject("ADODB.Stream") ADS.Open ADS.Type = 1 ADS.LoadFromFile(StrFileName) Data=ADS.Read Fsize=Clng(lenb(Data)) If Err Then Response.Write("<h2>错误提示: </h2>" & err.Description & "") Response.End End If ADS.Close If Response.IsClientConnected Then If FileType="gif" Or FileType="jpg" Or FileType="jpeg" Or FileType="bmp" Then Response.ContentType = "image/*" Else Response.AddHeader "Content-Disposition", "attachment; filename=" & TempFileName Response.ContentType = "application/ms-download" End If Response.AddHeader "Content-Length", Fsize Response.CharSet = "GB2312" Response.ContentType = "application/octet-stream" Response.BinaryWrite Data Response.Flush End If End Function Function ChkFile(FileName) Dim Temp,FileType ChkFile=False FileType=Lcase(Split(FileName,".")(ubound(Split(FileName,".")))) Temp="|asp|aspx|cgi|php|cdx|cer|asa|mdb|" If Instr(Temp,"|"&FileType&"|")>0 Then ChkFile=True End Function %>
更多的[分享]ASP图片防盗链代码请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2009-11-14
|
|
|