无惧文件上传类 Version V1.2

<%
'----------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'版权声明:版权所有,源代码公开,各种用途均可免费使用,但是修改后必须把修改后的文件
'发送一份给作者.并且保留作者此版权信息
'**********************************************************************
'----------------------------------------------------------------------
Dim oUpFileStream
'----------------------------------------------------------------------
'文件上传类
Class UpFile_Class

Dim Form,File,Version,Err

Private Sub Class_Initialize
 Version = "无惧上传类 Version V1.2"
 Err = -1
End Sub

Private Sub Class_Terminate 
  '清除变量及对像
  If Err < 0 Then
    Form.RemoveAll
    Set Form = Nothing
    File.RemoveAll
    Set File = Nothing
    oUpFileStream.Close
    Set oUpFileStream = Nothing
  End If
End Sub
  
Public Sub GetData (MaxSize)
  '定义变量
  Dim RequestBinData,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
  Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
  Dim iFindStart,iFindEnd
  Dim iFormStart,iFormEnd,sFormName
  '代码开始
  If Request.TotalBytes < 1 Then  '如果没有数据上传
    Err = 1
    Exit Sub
  End If
  If MaxSize > 0 Then '如果限制大小
    If Request.TotalBytes > MaxSize Then
    Err = 2 '如果上传的数据超出限制
    Exit Sub
    End If
  End If
  Set Form = Server.CreateObject ("Scripting.Dictionary")
  Form.CompareMode = 1
  Set File = Server.CreateObject ("Scripting.Dictionary")
  File.CompareMode = 1
  Set tStream = Server.CreateObject ("ADODB.Stream")
  Set oUpFileStream = Server.CreateObject ("ADODB.Stream")
  oUpFileStream.Type = 1
  oUpFileStream.Mode = 3
  oUpFileStream.Open
  oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
  oUpFileStream.Position = 0
  RequestBinData = oUpFileStream.Read
  iFormEnd = oUpFileStream.Size
  bCrLf = ChrB (13) & ChrB (10)
  '取得每个项目之间的分隔符
  sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1)
  iStart = LenB  (sSpace)
  iFormStart = iStart+2
  '分解项目
  Do
    iInfoEnd = InStrB (iFormStart,RequestBinData,bCrLf & bCrLf)+3
    tStream.Type = 1
    tStream.Mode = 3
    tStream.Open
    oUpFileStream.Position = iFormStart
    oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
    tStream.Position = 0
    tStream.Type = 2
    tStream.CharSet = "gb2312"
    sInfo = tStream.ReadText     
    '取得表单项目名称
    iFormStart = InStrB (iInfoEnd,RequestBinData,sSpace)-1
    iFindStart = InStr (22,sInfo,"name=""",1)+6
    iFindEnd = InStr (iFindStart,sInfo,"""",1)
    sFormName = Mid  (sinfo,iFindStart,iFindEnd-iFindStart)
    '如果是文件
    If InStr  (45,sInfo,"filename=""",1) > 0 Then
      Set oFileInfo = new FileInfo_Class
      '取得文件属性
      iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
      iFindEnd = InStr (iFindStart,sInfo,"""",1)
      sFileName = Mid  (sinfo,iFindStart,iFindEnd-iFindStart)
      oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "")+1)
      oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, ""))
      oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)
      iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
      iFindEnd = InStr (iFindStart,sInfo,vbCr)
      oFileInfo.FileType = Mid  (sinfo,iFindStart,iFindEnd-iFindStart)
      oFileInfo.FileStart = iInfoEnd
      oFileInfo.FileSize = iFormStart -iInfoEnd -2
      oFileInfo.FormName = sFormName
      file.add sFormName,oFileInfo
    else
    '如果是表单项目
      tStream.Close
      tStream.Type = 1
      tStream.Mode = 3
      tStream.Open
      oUpFileStream.Position = iInfoEnd
      oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
      tStream.Position = 0
      tStream.Type = 2
      tStream.CharSet = "gb2312"
      sFormValue = tStream.ReadText
      If Form.Exists (sFormName) Then
        Form (sFormName) = Form (sFormName) & ", " & sFormValue
        else
        form.Add sFormName,sFormValue
      End If
    End If
    tStream.Close
    iFormStart = iFormStart+iStart+2
    '如果到文件尾了就退出
  Loop Until  (iFormStart+2) >= iFormEnd
  RequestBinData = ""
  Set tStream = Nothing
End Sub
End Class

'------------------------------------------------------------------------------
'文件属性类
Class FileInfo_Class
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
'保存文件方法
Public Function SaveToFile (Path)
 if lcase((right(Path,3))<>lcase(FileExt)) then '经典的上传漏洞^_^
  response.Write ("<script language=javascript>alert('www.111cn.net:不允许上传这种文件!');</script>")
  response.end
 end if
  On Error Resume Next
  Dim oFileStream
  Set oFileStream = CreateObject ("ADODB.Stream")
  oFileStream.Type = 1
  oFileStream.Mode = 3
  oFileStream.Open
  oUpFileStream.Position = FileStart
  oUpFileStream.CopyTo oFileStream,FileSize
  oFileStream.SaveToFile Path,2
  oFileStream.Close
  Set oFileStream = Nothing
End Function
 
'取得文件数据
Public Function FileData
  oUpFileStream.Position = FileStart
  FileData = oUpFileStream.Read (FileSize)
End Function

End Class
%>

时间: 2024-09-20 16:52:16

无惧文件上传类 Version V1.2的相关文章

asp 无组件文件上传类

<% '---------------------------------------------------------------------- Dim oUpFileStream '---------------------------------------------------------------------- '文件上传类 Class UpFile_Class Dim Form,File,Version,Err Private Sub Class_Initialize  Ver

Asp无组件文件上传的实例

上传|无组件 1.库文件(upload.inc.asp)<%Dim oUpFileStream Class UpFile_Class Dim Form,File,Version,Err Private Sub Class_InitializeVersion = "无组件上传类 Version V1.0"Err = -1End Sub Private Sub Class_Terminate '清除变量及对像If Err < 0 ThenForm.RemoveAllSet Fo

asp无组件文件上传代码

<%Server.ScriptTimeOut=5000%> <!--#include file="upload_wj.inc"--> <% dim upload, file, maxWidth, maxHeight, oFileStream, bytes, ratio1, ratio2 set upload = new upload_file set file = upload.file("pic") maxWidth = CInt(u

asp 文件上传类代码

dim oUpFileStream Class upload_file   dim Form,File,Version   Private Sub Class_Initialize    '定义变量   dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo   dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName   dim iF

PHP实现的多文件上传类及用法示例_php技巧

本文实例讲述了PHP实现的多文件上传类及用法.分享给大家供大家参考,具体如下: 1.upFiles.css.php 文件 <?php class UploadFiles{ private $maxsize = '1000000'; //允许上传文件最大长度 private $allowtype = array('jpg','png','gif','jpeg');//允许上传文件类型 private $israndfile = true;//是否随机文件名 private $filepath;//

Php文件上传类class.upload.php用法示例

简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮助你快速的给自己的网站集成上传文件功能.不仅如此,此分类还有一些列的处理功能,可以对上传的文件或者本地的文件进行处理,其图片处理功能比较 强大,包括图片的缩放.旋转.剪裁.类型转换.应用滤镜.添加边框文字和水印等.支持的图片类型是png.jpg.gif和bmp. 使用方法 首先我们要有一个用于提交上传文件的表单,如下,注意表单要写上enctype="multipart/form-data".  代码如

ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法_php实例

本文实例讲述了ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法.分享给大家供大家参考.具体实现方法分析如下: 首先,AjaxFileUploader插件是一个基于jquery的插件,我们可以使用AjaxFileUploader插件来实现文件异步上传功能了,使用这款插件上传文件不要担心兼容性的问题,它的兼容性可以说兼容所有主流浏览器,下面来给大家介绍一个AjaxFileUploader+thinkphp实现文件上传的实例. ThinkPHP框架下用AjaxFileUpl

ThinkPHP结合AjaxFileUploader实现无刷新文件上传

ThinkPHP框架下用AjaxFileUploader插件实现ajax文件上传,支持多种文件格式,页面无刷新上传. 在Lib/Action/目录下创建upAction.class.php文件,代码如下:  代码如下 复制代码 <!--?php class upAction extends BaseAction{   public function index(){     $this--->display(); }   /* *@文件上传 *@author    FineYi *@date 

ajax+php 无刷新文件上传代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/1999/xhtml"> <head> <meta http-equiv="conte