[ Index ]
 

Code source de FCKeditor 2.4

Accdez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/filemanager/upload/asp/ -> class_upload.asp (source)

   1  <!--
   2   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4   * 
   5   * == BEGIN LICENSE ==
   6   * 
   7   * Licensed under the terms of any of the following licenses at your
   8   * choice:
   9   * 
  10   *  - GNU General Public License Version 2 or later (the "GPL")
  11   *    http://www.gnu.org/licenses/gpl.html
  12   * 
  13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14   *    http://www.gnu.org/licenses/lgpl.html
  15   * 
  16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  17   *    http://www.mozilla.org/MPL/MPL-1.1.html
  18   * 
  19   * == END LICENSE ==
  20   * 
  21   * File Name: class_upload.asp
  22   *     These are the classes used to handle ASP upload without using third
  23   *     part components (OCX/DLL).
  24   * 
  25   * File Authors:
  26   *         NetRube (netrube@126.com)
  27  -->
  28  <%
  29  '**********************************************
  30  ' File:        NetRube_Upload.asp
  31  ' Version:    NetRube Upload Class Version 2.1 Build 20050228
  32  ' Author:    NetRube
  33  ' Email:    NetRube@126.com
  34  ' Date:        02/28/2005
  35  ' Comments:    The code for the Upload.
  36  '            This can free usage, but please
  37  '            not to delete this copyright information.
  38  '            If you have a modification version,
  39  '            Please send out a duplicate to me.
  40  '**********************************************
  41  ' 文件名:    NetRube_Upload.asp
  42  ' 版本:        NetRube Upload Class Version 2.1 Build 20050228
  43  ' 作者:        NetRube(网络乡巴佬)
  44  ' 电子邮件:    NetRube@126.com
  45  ' 日期:        2005年02月28日
  46  ' 声明:        文件上传类
  47  '            本上传类可以自由使用,但请保留此版权声明信息
  48  '            如果您对本上传类进行修改增强,
  49  '            请发送一份给俺。
  50  '**********************************************
  51  
  52  Class NetRube_Upload
  53  
  54      Public    File, Form
  55      Private oSourceData
  56      Private nMaxSize, nErr, sAllowed, sDenied
  57      
  58      Private Sub Class_Initialize
  59          nErr        = 0
  60          nMaxSize    = 1048576
  61          
  62          Set File            = Server.CreateObject("Scripting.Dictionary")
  63          File.CompareMode    = 1
  64          Set Form            = Server.CreateObject("Scripting.Dictionary")
  65          Form.CompareMode    = 1
  66          
  67          Set oSourceData        = Server.CreateObject("ADODB.Stream")
  68          oSourceData.Type    = 1
  69          oSourceData.Mode    = 3
  70          oSourceData.Open
  71      End Sub
  72      
  73      Private Sub Class_Terminate
  74          Form.RemoveAll
  75          Set Form = Nothing
  76          File.RemoveAll
  77          Set File = Nothing
  78          
  79          oSourceData.Close
  80          Set oSourceData = Nothing
  81      End Sub
  82      
  83      Public Property Get Version
  84          Version = "NetRube Upload Class Version 1.0 Build 20041218"
  85      End Property
  86  
  87      Public Property Get ErrNum
  88          ErrNum    = nErr
  89      End Property
  90      
  91      Public Property Let MaxSize(nSize)
  92          nMaxSize    = nSize
  93      End Property
  94      
  95      Public Property Let Allowed(sExt)
  96          sAllowed    = sExt
  97      End Property
  98      
  99      Public Property Let Denied(sExt)
 100          sDenied    = sExt
 101      End Property
 102  
 103      Public Sub GetData
 104          Dim aCType
 105          aCType = Split(Request.ServerVariables("HTTP_CONTENT_TYPE"), ";")
 106          If aCType(0) <> "multipart/form-data" Then
 107              nErr = 1
 108              Exit Sub
 109          End If
 110          
 111          Dim nTotalSize
 112          nTotalSize    = Request.TotalBytes
 113          If nTotalSize < 1 Then
 114              nErr = 2
 115              Exit Sub
 116          End If
 117          If nMaxSize > 0 And nTotalSize > nMaxSize Then
 118              nErr = 3
 119              Exit Sub
 120          End If
 121          
 122          oSourceData.Write Request.BinaryRead(nTotalSize)
 123          oSourceData.Position = 0
 124          
 125          Dim oTotalData, oFormStream, sFormHeader, sFormName, bCrLf, nBoundLen, nFormStart, nFormEnd, nPosStart, nPosEnd, sBoundary
 126          
 127          oTotalData    = oSourceData.Read
 128          bCrLf        = ChrB(13) & ChrB(10)
 129          sBoundary    = MidB(oTotalData, 1, InStrB(1, oTotalData, bCrLf) - 1)
 130          nBoundLen    = LenB(sBoundary) + 2
 131          nFormStart    = nBoundLen
 132          
 133          Set oFormStream = Server.CreateObject("ADODB.Stream")
 134          
 135          Do While (nFormStart + 2) < nTotalSize
 136              nFormEnd    = InStrB(nFormStart, oTotalData, bCrLf & bCrLf) + 3
 137              
 138              With oFormStream
 139                  .Type    = 1
 140                  .Mode    = 3
 141                  .Open
 142                  oSourceData.Position = nFormStart
 143                  oSourceData.CopyTo oFormStream, nFormEnd - nFormStart
 144                  .Position    = 0
 145                  .Type        = 2
 146                  .CharSet    = "UTF-8"
 147                  sFormHeader    = .ReadText
 148                  .Close
 149              End With
 150              
 151              nFormStart    = InStrB(nFormEnd, oTotalData, sBoundary) - 1
 152              nPosStart    = InStr(22, sFormHeader, " name=", 1) + 7
 153              nPosEnd        = InStr(nPosStart, sFormHeader, """")
 154              sFormName    = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
 155              
 156              If InStr(45, sFormHeader, " filename=", 1) > 0 Then
 157                  Set File(sFormName)            = New NetRube_FileInfo
 158                  File(sFormName).FormName    = sFormName
 159                  File(sFormName).Start        = nFormEnd
 160                  File(sFormName).Size        = nFormStart - nFormEnd - 2
 161                  nPosStart                    = InStr(nPosEnd, sFormHeader, " filename=", 1) + 11
 162                  nPosEnd                        = InStr(nPosStart, sFormHeader, """")
 163                  File(sFormName).ClientPath    = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
 164                  File(sFormName).Name        = Mid(File(sFormName).ClientPath, InStrRev(File(sFormName).ClientPath, "\") + 1)
 165                  File(sFormName).Ext            = LCase(Mid(File(sFormName).Name, InStrRev(File(sFormName).Name, ".") + 1))
 166                  nPosStart                    = InStr(nPosEnd, sFormHeader, "Content-Type: ", 1) + 14
 167                  nPosEnd                        = InStr(nPosStart, sFormHeader, vbCr)
 168                  File(sFormName).MIME        = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
 169              Else
 170                  With oFormStream
 171                      .Type    = 1
 172                      .Mode    = 3
 173                      .Open
 174                      oSourceData.Position = nPosEnd
 175                      oSourceData.CopyTo oFormStream, nFormStart - nFormEnd - 2
 176                      .Position    = 0
 177                      .Type        = 2
 178                      .CharSet    = "UTF-8"
 179                      Form(sFormName)    = .ReadText
 180                      .Close
 181                  End With
 182              End If
 183              
 184              nFormStart    = nFormStart + nBoundLen
 185          Loop
 186          
 187          oTotalData = ""
 188          Set oFormStream = Nothing
 189      End Sub
 190  
 191      Public Sub SaveAs(sItem, sFileName)
 192          If File(sItem).Size < 1 Then
 193              nErr = 2
 194              Exit Sub
 195          End If
 196          
 197          If Not IsAllowed(File(sItem).Ext) Then
 198              nErr = 4
 199              Exit Sub
 200          End If
 201          
 202          Dim oFileStream
 203          Set oFileStream = Server.CreateObject("ADODB.Stream")
 204          With oFileStream
 205              .Type        = 1
 206              .Mode        = 3
 207              .Open
 208              oSourceData.Position = File(sItem).Start
 209              oSourceData.CopyTo oFileStream, File(sItem).Size
 210              .Position    = 0
 211              .SaveToFile sFileName, 2
 212              .Close
 213          End With
 214          Set oFileStream = Nothing
 215      End Sub
 216      
 217      Private Function IsAllowed(sExt)
 218          Dim oRE
 219          Set oRE    = New RegExp
 220          oRE.IgnoreCase    = True
 221          oRE.Global        = True
 222          
 223          If sDenied = "" Then
 224              oRE.Pattern    = sAllowed
 225              IsAllowed    = (sAllowed = "") Or oRE.Test(sExt)
 226          Else
 227              oRE.Pattern    = sDenied
 228              IsAllowed    = Not oRE.Test(sExt)
 229          End If
 230          
 231          Set oRE    = Nothing
 232      End Function
 233  End Class
 234  
 235  Class NetRube_FileInfo
 236      Dim FormName, ClientPath, Path, Name, Ext, Content, Size, MIME, Start
 237  End Class
 238  %>


Gnr le : Sun Feb 25 15:28:05 2007 par Balluche grce PHPXref 0.7