· 我们在管理网站文件时,能把扩展名相同的文件放在同一个目录下,起一个比较特别名字,例如放pdf文件目录为the_pdf_file_s,把下面代码另存为down.asp,他的网上路径为 /down.asp,我们就能用// /down.asp?FileName=51windows.pdf来下载这个文件了,而且下载者无法看到这个文件实际下载路径的!在down.asp中我们还能设置下载文件是否需要登陆,判断下载的来源页是否为外部网站,从而能做到防止文件被盗链。 示例代码:
以下是引用片段:
以下是引用片段: <% From_url = Cstr(Request.ServerVariables("HTTP_REFERER")) Serv_url = Cstr(Request.ServerVariables("SERVER_NAME")) if mid(From_url,8,len(Serv_url)) <> Serv_url then response.write "非法链接!" ’防止盗链 response.end end if if Request.Cookies("Logined")="" then response.redirect "/login.asp" ’需要登陆! end if Function GetFileName(longname)’/folder1/folder2/file.asp=>file.asp while instr(longname,"/") longname = right(longname,len(longname)-1) wend GetFileName = longname End Function Dim Stream Dim Contents Dim FileName Dim TrueFileName Dim FileExt Const adTypeBinary = 1 FileName = Request.QueryString("FileName") if FileName = "" Then Response.Write "无效文件名!" Response.End End if FileExt = Mid(FileName, InStrRev(FileName, ".") + 1) Select Case UCase(FileExt) Case "ASP", "ASA", "ASPX", "ASAX", "MDB" Response.Write "非法操作!" Response.End End Select Response.Clear if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then Response.ContentType = "image/*" ’对图像文件不出现下载对话框 else Response.ContentType = "application/ms-download" end if Response.AddHeader "content-disposition", "attachment; filename=" & GetFileName(Request.QueryString("FileName")) Set Stream = server.CreateObject("ADODB.Stream") Stream.Type = adTypeBinary Stream.Open if lcase(right(FileName,3))="pdf" then ’设置pdf类型文件目录 TrueFileName = "/the_pdf_file_s/"&FileName end if if lcase(right(FileName,3))="doc" then ’设置DOC类型文件目录 TrueFileName = "/my_D_O_C_file/"&FileName end if if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then TrueFileName = "/all_images_/"&FileName ’设置图像文件目录 end if Stream.LoadFromFile Server.MapPath(TrueFileName) While Not Stream.EOS Response.BinaryWrite Stream.Read(1024 * 64) Wend Stream.Close Set Stream = Nothing Response.Flush Response.End %> |
本地图片,音乐等ASP防盗链代码(asp) 以下是引用片段:
以下是引用片段: <% ’定义函数,用ADODB.Stream读取二进制数据 Function ReadBinaryFile(FileName) Const adTypeBinary = 1 Dim BinaryStream Set BinaryStream = CreateObject("ADODB.Stream") BinaryStream.Type = adTypeBinary BinaryStream.Open BinaryStream.LoadFromFile FileName ReadBinaryFile = BinaryStream.Read End Function Response.AddHeader "Content-Disposition", "attachment;filename=2.gif"’文件名 Response.ContentType = "image/GIF" ’设置(1) response.Binarywrite ReadBinaryFile(server.mappath("2.gif"))’就是你读取存在本地的文件,防止被 别人知道真实路径盗连的。 %> |
这希望对你有所帮助!!!
香港ceranetworks提速啦是成立于2012年的十分老牌的一个商家这次给大家评测的是 香港ceranetworks 8核16G 100M 这款产品 提速啦老板真的是豪气每次都给高配我测试 不像别的商家每次就给1核1G,废话不多说开始跑脚本。香港ceranetworks 2核2G 50G硬盘20M 69元/月30M 99元/月50M 219元/月100M 519元/月香港ceranetwork...
易探云怎么样?易探云隶属于纯乐电商旗下网络服务品牌,香港NTT Communications合作伙伴,YiTanCloud Limited旗下合作云计算品牌,数十年云计算行业经验。发展至今,我们已凝聚起港内领先的开发和运维团队,积累起4年市场服务经验,提供电话热线/在线咨询/服务单系统等多种沟通渠道,7*24不间断服务,3分钟快速响应。目前,易探云提供香港大带宽20Mbps、16G DDR3内存、...
【双十二】兆赫云:全场vps季付六折优惠,低至50元/季,1H/1G/30M/20G数据盘/500G流量/洛杉矶联通9929商家简介:兆赫云是一家国人商家,成立2020年,主要业务是美西洛杉矶联通9929线路VPS,提供虚拟主机、VPS和独立服务器。VPS采用KVM虚拟架构,线路优质,延迟低,稳定性强。是不是觉得黑五折扣力度不够大?还在犹豫徘徊中?这次为了提前庆祝双十二,特价推出全场季付六折优惠。...