设为首页
收藏本站
最新电影
> 子栏目 Asp | Jsp | XML | XSL | Div+Css | 自定义函数 | 数据库 | 脚本特效
您现在的位置: 首页=>后台技术=>Asp 订阅本栏目  
防盗链下载
时间: 2007-09-23 08:51:29 阅读次数:2651





以下是代码片段:
<%   
  Response.Buffer   =   true   
  Response.Clear   
  
  '###############################################################
  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   
  '##############################################################3
  
  '获取要下载的文件在服务器上的绝对位置   
  dlfile=trim(request("dlfile"))   
      If   dlfile<>""   Then   
       fileurl=server.MapPath(dlfile)   
      Else   
       Response.end   
      End   If   
    
  '创建Myfso,使用FSO组件   
      Set   Myfso=Server.CreateObject("Scripting.FileSystemObject")   
      Set   f=Myfso.getfile(fileurl)   '定义FSO对象f   
          fsize=f.size   '文件大小   
          fName=f.name   '文件名字   
      Set   f=Nothing     '释放f   
      Set   Myfso=Nothing   '释放MyFso   
    
  '使用Adodb.Stream组件   
  Set   MyStream   =   Server.CreateObject("ADODB.Stream")   
  MyStream.Open   
  MyStream.Type   =   1   
  MyStream.LoadFromFile   fileurl   
    
  '读取文件类型,让系统识别,以存为不同类型的文件   
  Select   Case   lcase(Right(fName,   4))   
      Case   ".asf"   
  ContentType   =   "video/x-ms-asf"   
      Case   ".avi"   
  ContentType   =   "video/avi"   
      Case   ".doc"   
  ContentType   =   "application/msword"   
      Case   ".zip"   
  ContentType   =   "application/zip"   
      Case   ".xls"   
  ContentType   =   "application/vnd.ms-excel"   
      Case   ".gif"   
  ContentType   =   "image/gif"   
      Case   ".jpg",   "jpeg"   
  ContentType   =   "image/jpeg"   
      Case   ".wav"   
  ContentType   =   "audio/wav"   
      Case   ".mp3"   
  ContentType   =   "audio/mpeg3"   
      Case   ".mpg",   "mpeg"   
  ContentType   =   "video/mpeg"   
      Case   ".rtf"   
  ContentType   =   "application/rtf"   
      Case   ".htm",   "html"   
  ContentType   =   "text/html"   
      Case   ".asp"   
  ContentType   =   "text/html"   
      Case   ".txt"   
  ContentType   =   "text/plain"   
      Case   Else   
  ContentType   =   "application/octet-stream"   
      End   Select   
    
  '下载   
  Response.AddHeader   "Content-Disposition",   "attachment;   filename="   &   fName   
  Response.AddHeader   "Content-Length",   fsize   
  Response.Charset   =   "UTF-8"   
  Response.ContentType   =   ContentType   
  Response.BinaryWrite   MyStream.Read   
  Response.Flush   
    
  '释放MyStream   
  MyStream.Close   
  Set   MyStream   =   Nothing   
  %>   
  ********************************   
  然后你在要实现的页面中这样调用:   
    
  *****************************************   
  <a   href="dl.asp?dlfile=dl.doc">dl.doc</a>   
  *****************************************   
  本源码程序可以下载各种文件,包括asp源码、mp3、htm、TXT等等飞!飞Asp技术乐园



站内搜索    

下一篇动网论坛数据库结构参考

上一篇vbscript Asc 函数 使用介绍

本栏目最新 栏目最新列表
HTTP 401.5 - 未经授权:ISAPI/CGI 应用程序
Asp使用FSO写UTF-8编码文件的方法
asp操作,控制excel的方法
让ewebeditor兼容ie8的方法
Asp实现二级域名的方法
网站优化策划 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新 站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息  
MIME介绍 及 [1] [2] [3]
巧用Google和迅雷来下载
Transact SQL 常 [1] [2]
VIA Rhine II Fast Ethe
电脑常用端 [1] [2] [3]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
每日一句:A friend and
每日一句:Theres no tu
经典__悟透JavaScript
相关文章
防盗链下载
ASP简单防盗链方法谈
 
 width= 
伟哥博客 西安房产 123最新电影 三四六四