论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

asp打包类

文章类别:Asp | 发表日期:2009-8-3 11:29:29

asp打包类

调用:

 程序代码
<%
On Error Resume Next
Dim r
Set r = New Rar

r.Add Server.MapPath("a.gIf")
r.Add Server.MapPath("a.txt")
r.Add Server.MapPath("test")
r.Add Server.MapPath("file.asp")
r.packname = Server.MapPath("xxx.dat")
r.Pack
r.rootpath = Server.MapPath("xxx")
r.packname = Server.MapPath("xxx.dat")
r.UnPack

Response.Write(Err.Description)
Set r = Nothing
%>


类代码:

 程序代码

<script Language="Vbscript" Runat="server">
Class Rar
Dim files,packname,s,s1,s2,rootpath,fso,f,buf
Private Sub Class_Initialize
  Randomize
  Dim ranNum
  ranNum = Int(90000 * Rnd) + 10000
  packname = Year(Now)&Month(Now)&Day(Now)&Hour(Now)&Minute(Now)&Second(Now)&ranNum&".asp2004"

  rootpath = Server.MapPath("./")

  Set files = server.CreateObject("Scripting.Dictionary")
  Set fso = Server.CreateObject("Scripting.FileSystemObject")

  Set s = server.CreateObject("ADODB.Stream"):s.Open:s.Type = 1
  Set s1 = server.CreateObject("ADODB.Stream"):s1.Open:s1.Type = 1
  Set s2 = server.CreateObject("ADODB.Stream"):s2.Open:s2.Type = 2
End Sub

Private Sub Class_Terminate
  s.Close:Set s = Nothing
  s1.Close:Set s1 = Nothing
  s2.Close:Set s2 = Nothing

  Set fso = Nothing
End Sub

Public Sub Add(obj)
  If fso.FileExists(obj) Then
   Set f = fso.GetFile(obj)
   files.Add obj,f.Size
  ElseIf fso.FolderExists(obj) Then
   files.Add obj,-1
   Set f = fso.GetFolder(obj)
   Set fc = f.Files
   For Each f1 in fc
    Add(LCase(f1.Path))
   Next
  End If
End Sub
http://www.devdao.com/
Public Sub Pack
  Dim str
  a = files.Keys
  b = files.Items
  for i=0 to files.count-1
   If b(i)>=0 Then
    s.LoadFromFile(a(i))
    buf = s.Read
    If Not IsNull(buf) Then s1.Write(buf)
   End If
   str = str & b(i)&">"&Replace(a(i),rootpath,"")&vbCrLf
  next
  str = CStr(Right("000000000"&len(str),10)) & str
  buf = TextToStream(str)
  s.Position = 0
  s.Write buf
  s1.Position = 0
  s.Write s1.Read
  s.SetEOS
  s.SaveToFile(packname)
End Sub

Public Sub UnPack

  If Not fso.FolderExists(rootpath) Then
   fso.CreateFolder(rootpath)
  End If
  Dim size
  '转换文件大小
  s.LoadFromFile(packname)
  size = CInt(StreamToText(s.Read(10)))
  str = StreamToText(s.Read(size))
  arr = Split(str,vbCrLf)

  for i=0 to Ubound(arr)-1
   arrFile = Split(arr(i),">")
   If arrFile(0) < 0 Then
    If Not fso.FolderExists(rootpath&arrFile(1)) Then
     fso.CreateFolder(rootpath&arrFile(1))
    End If
   ElseIf arrFile(0) >= 0 Then
    If fso.FileExists(rootpath&arrFile(1)) Then
     fso.DeleteFile(rootpath&arrFile(1))
    End If
    s1.Position = 0
    buf = s.Read(arrFile(0))
    If Not IsNull(buf) Then s1.Write(buf)
    s1.SetEOS
    s1.SaveToFile(rootpath&arrFile(1))
   End If
  Next
End Sub

Public Function StreamToText(stream)
  If IsNull(stream) Then
   StreamToText = ""
  Else
   Set sm = server.CreateObject("ADODB.Stream"):sm.Open:sm.Type = 1
   sm.Write(stream)
   sm.Position = 0
   sm.Type = 2
   sm.charset = "gb2312"
   sm.Position = 0
   StreamToText = sm.ReadText()
   sm.Close:Set sm = Nothing
  End If
End Function

Public Function TextToStream(text)
  If text="" Then
   TextToStream = "" '这里该如何写?空流?
  Else
   Set sm = server.CreateObject("ADODB.Stream"):sm.Open:sm.Type = 2:sm.charset = "gb2312"
   sm.WriteText(text)
   sm.Position = 0
   sm.Type = 1
   sm.Position = 0
   TextToStream = sm.Read
   sm.Close:Set sm = Nothing
  End If
End Function
End Class
</script>

视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058