ASP无组件上载,带进度条,多文件上载。。

各种ASP无组件上载,带进度条的实在太多,用起来也不方便,今天自己写了一个,希望大家给点意见

页面都是UTF-8 编码的,用的时候可根据自己页面编码转换

核心编码:SundyUpload.asp
例子:Example.asp

SundyUpload.asp代码如下:

< meta http - equiv = " Content-Type "  content = " text/html; charset=utf-8 "   />
< %
Dim  SundyUpload_SourceData
Class SundyUpload
  
Dim  objForm,objFile,Version,objProgress
    
Dim  xmlPath,CharsetEncoding
  
Public   Function  Form(strForm)
    strForm
= lcase (strForm)
    
If   NOT  objForm.exists(strForm)  Then
      Form
= ""
    
Else
      Form
= objForm(strForm)
    
End   If
  
End Function

  
Public   Function  File(strFile)
    strFile
= lcase (strFile)
    
If   NOT  objFile.exists(strFile)  Then
      
Set  File = new  FileInfo
    
Else
      
Set  File = objFile(strFile)
    
End   If
  
End Function
  
    
Public   Sub  UploadInit(progressXmlPath,charset)
    
Dim  RequestData,sStart,Crlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
        
Dim  iFileSize,sFilePath,sFileType,sFormValue,sFileName
        
Dim  iFindStart,iFindEnd
        
Dim  iFormStart,iFormEnd,sFormName
      
        Version
= " Upload Width Progress Bar Version 1.0 "
        
Set  objForm = Server.CreateObject( " Scripting.Dictionary " )
        
Set  objFile = Server.CreateObject( " Scripting.Dictionary " )
        
If  Request.TotalBytes < 1   Then   Exit   Sub
        
Set  tStream  =  Server.CreateObject( " adodb.stream " )
        
Set  SundyUpload_SourceData  =  Server.CreateObject( " adodb.stream " )
        SundyUpload_SourceData.Type 
=   1
        SundyUpload_SourceData.Mode 
= 3
        SundyUpload_SourceData.Open
        
        
Dim  TotalBytes
        
Dim  ChunkReadSize
        
Dim  DataPart, PartSize
        
Dim  objProgress
        
        TotalBytes 
=  Request.TotalBytes      '  总大小
        ChunkReadSize  =   64   *   1024      '  分块大小64K
        BytesRead  =   0
        xmlPath 
=  progressXmlPath
        CharsetEncoding 
=  charset
        
If  CharsetEncoding  =   ""   Then
          CharsetEncoding 
=   " utf-8 "
        
End   If
        
Set  objProgress  =   New  Progress
        objProgress.ProgressInit(xmlPath)
        objProgress.UpdateProgress Totalbytes,
0
        
' 循环分块读取
         Do   While  BytesRead  <  TotalBytes
            
' 分块读取
            PartSize  =  ChunkReadSize
            
If  PartSize  +  BytesRead  >  TotalBytes  Then  PartSize  =  TotalBytes  -  BytesRead
            DataPart 
=  Request.BinaryRead(PartSize)
            BytesRead 
=  BytesRead  +  PartSize
    
            SundyUpload_SourceData.Write DataPart
            
            objProgress.UpdateProgress Totalbytes,BytesRead 
        
Loop
        
' SundyUpload_SourceData.Write  Request.BinaryRead(Request.TotalBytes)
        SundyUpload_SourceData.Position = 0
        RequestData 
= SundyUpload_SourceData.Read 
    
        iFormStart 
=   1
        iFormEnd 
=  LenB(RequestData)
        Crlf 
=  chrB( 13 &  chrB( 10 )
        sStart 
=  MidB(RequestData, 1 , InStrB(iFormStart,RequestData,Crlf) - 1 )
        iStart 
=  LenB (sStart)
        iFormStart
= iFormStart + iStart + 1
        
While  (iFormStart  +   10 <  iFormEnd 
            iInfoEnd 
=  InStrB(iFormStart,RequestData,Crlf  &  Crlf) + 3
            tStream.Type 
=   1
            tStream.Mode 
= 3
            tStream.Open
            SundyUpload_SourceData.Position 
=  iFormStart
            SundyUpload_SourceData.CopyTo tStream,iInfoEnd
- iFormStart
            tStream.Position 
=   0
            tStream.Type 
=   2
            tStream.Charset 
= CharsetEncoding
            sInfo 
=  tStream.ReadText
            tStream.Close
            
' 取得表单项目名称
            iFormStart  =  InStrB(iInfoEnd,RequestData,sStart)
            iFindStart 
=   InStr ( 22 ,sInfo, " name="" " , 1 ) + 6
            iFindEnd 
=   InStr (iFindStart,sInfo, " "" " , 1 )
            sFormName 
=   lcase ( Mid  (sinfo,iFindStart,iFindEnd - iFindStart))
            
' 如果是文件
             If   InStr  ( 45 ,sInfo, " filename="" " , 1 >   0   Then
                
Set  theFile = new  FileInfo
                
' 取得文件名
                iFindStart  =   InStr (iFindEnd,sInfo, " filename="" " , 1 ) + 10
                iFindEnd 
=   InStr (iFindStart,sInfo, " "" " , 1 )
                sFileName 
=   Mid  (sinfo,iFindStart,iFindEnd - iFindStart)
                theFile.FileName
= getFileName(sFileName)
                theFile.FilePath
= getFilePath(sFileName)
                
' 取得文件类型
                iFindStart  =   InStr (iFindEnd,sInfo, " Content-Type:  " , 1 ) + 14
                iFindEnd 
=   InStr (iFindStart,sInfo,vbCr)
                theFile.FileType 
= Mid  (sinfo,iFindStart,iFindEnd - iFindStart)
                theFile.FileStart 
= iInfoEnd
                theFile.FileSize 
=  iFormStart  - iInfoEnd  - 3
                theFile.FormName
= sFormName
                
If   NOT  objFile.Exists(sFormName)  Then
                    objFile.add sFormName,theFile
                
End   If
            
Else
                
' 如果是表单项目
                tStream.Type  = 1
                tStream.Mode 
= 3
                tStream.Open
                SundyUpload_SourceData.Position 
=  iInfoEnd 
                SundyUpload_SourceData.CopyTo tStream,iFormStart
- iInfoEnd - 3
                tStream.Position 
=   0
                tStream.Type 
=   2
                tStream.Charset 
=  CharsetEncoding
                sFormValue 
=  tStream.ReadText 
                tStream.Close
                
If  objForm.Exists(sFormName)  Then
                    objForm(sFormName)
= objForm(sFormName) & " " & sFormValue          
                
Else
                    objForm.Add sFormName,sFormValue
                
End   If
            
End   If
            iFormStart
= iFormStart + iStart + 1
        
Wend
        RequestData
= ""
        
Set  tStream  =   Nothing       
    
End Sub
    
Private   Sub  Class_Initialize 
        
    
End Sub
    
    
Private   Sub  Class_Terminate  
      
If  Request.TotalBytes > 0   Then
            objForm.RemoveAll
            objFile.RemoveAll
            
Set  objForm = Nothing
            
Set  objFile = Nothing
            SundyUpload_SourceData.Close
            
Set  SundyUpload_SourceData  =   Nothing
      
End   If
        
Set  objProgress  =   Nothing
        
Set  objFso  =  Server.CreateObject( " Scripting.FileSystemObject " )
        
If  objFso.FileExists(xmlPath)  Then
          objFso.DeleteFile(xmlPath)
        
End   If
        
Set  objFso  =   Nothing
    
End Sub
 
    
Private   Function  GetFilePath(FullPath)
        
If  FullPath  <>   ""   Then
          GetFilePath 
=   left (FullPath, InStrRev (FullPath,  " " ))
        
Else
          GetFilePath 
=   ""
        
End   If
    
End Function
 
    
Private   Function  GetFileName(FullPath)
        
If  FullPath  <>   ""   Then
          GetFileName 
=   mid (FullPath, InStrRev (FullPath,  " " ) + 1 )
        
Else
          GetFileName 
=   ""
        
End   If
    
End Function
End  Class

Class FileInfo
  
Dim  FormName,FileName,FilePath,FileSize,FileType,FileStart
  
Private   Sub  Class_Initialize 
    FileName 
=   ""
    FilePath 
=   ""
    FileSize 
=   0
    FileStart
=   0
    FormName 
=   ""
    FileType 
=   ""
  
End Sub
  
    
Public   Function  SaveAs(FullPath)
        
Dim  dr,ErrorChar,i
        SaveAs
= True
        
If   trim (fullpath) = ""   or  FileStart = 0   or  FileName = ""   or   right (fullpath, 1 ) = " / "   Then   Exit   Function
        
Set  dr = CreateObject ( " Adodb.Stream " )
        dr.Mode
= 3
        dr.Type
= 1
        dr.Open
        SundyUpload_SourceData.position
= FileStart
        SundyUpload_SourceData.copyto dr,FileSize
        dr.SaveToFile FullPath,
2
        dr.Close
        
Set  dr = Nothing  
        SaveAs
= False
    
End Function
End  Class

Class Progress
  
Dim  objDom,xmlPath
    
Dim  startTime
  
Private   Sub  Class_Initialize

    
End Sub
    
    
Public   Sub  ProgressInit(xmlPathTmp)
      
Dim  objRoot,objChild
        
Dim  objPI

        xmlPath 
=  xmlPathTmp
        
Set  objDom  =  Server.CreateObject( " Microsoft.XMLDOM " )
        
Set  objRoot  =  objDom.createElement( " progress " )
        objDom.appendChild objRoot
        
        
Set  objChild  =  objDom.createElement( " totalbytes " )
        objChild.Text 
=   " 0 "
        objRoot.appendChild objChild
        
Set  objChild  =  objDom.createElement( " uploadbytes " )
        objChild.Text 
=   " 0 "
        objRoot.appendChild objChild
        
Set  objChild  =  objDom.createElement( " uploadpercent " )
        objChild.Text 
=   " 0% "
        objRoot.appendChild objChild
        
Set  objChild  =  objDom.createElement( " uploadspeed " )
        objChild.Text 
=   " 0 "
        objRoot.appendChild objChild
        
Set  objChild  =  objDom.createElement( " totaltime " )
        objChild.Text 
=   " 00:00:00 "
        objRoot.appendChild objChild
        
Set  objChild  =  objDom.createElement( " lefttime " )
        objChild.Text 
=   " 00:00:00 "
        objRoot.appendChild objChild
        
        
Set  objPI  =  objDom.createProcessingInstruction( " xml " , " version='1.0' encoding='utf-8' " )
        objDom.insertBefore objPI, objDom.childNodes(
0 )
        objDom.Save xmlPath
        
Set  objPI  =   Nothing
        
Set  objChild  =   Nothing
        
Set  objRoot  =   Nothing
        
Set  objDom  =   Nothing
    
End Sub
    
    
Sub  UpdateProgress(tBytes,rBytes)
      
Dim  eTime,currentTime,speed,totalTime,leftTime,percent
        
If  rBytes  =   0   Then
            startTime 
=   Timer
            
Set  objDom  =  Server.CreateObject( " Microsoft.XMLDOM " )
            objDom.load(xmlPath)
            objDom.selectsinglenode(
" //totalbytes " ).text = tBytes
            objDom.save(xmlPath)
        
Else
          speed 
=   0.0001
          currentTime 
=   Timer
        eTime 
=  currentTime  -  startTime
            
If  eTime > 0   Then  speed  =  rBytes  /  eTime
            totalTime 
=  tBytes  /  speed
            leftTime 
=  (tBytes  -  rBytes)  /  speed
            percent 
=   Round (rBytes  * 100   /  tBytes)
            
' objDom.selectsinglenode("//uploadbytes").text = rBytes
             ' objDom.selectsinglenode("//uploadspeed").text = speed
             ' objDom.selectsinglenode("//totaltime").text = totalTime
             ' objDom.selectsinglenode("//lefttime").text = leftTime
            objDom.selectsinglenode( " //uploadbytes " ).text  =  FormatFileSize(rBytes)  &   "  /  "   &  FormatFileSize(tBytes)
            objDom.selectsinglenode(
" //uploadpercent " ).text  =  percent
            objDom.selectsinglenode(
" //uploadspeed " ).text  =  FormatFileSize(speed)  &   " /sec "
            objDom.selectsinglenode(
" //totaltime " ).text  =  SecToTime(totalTime)
            objDom.selectsinglenode(
" //lefttime " ).text  =  SecToTime(leftTime)
            objDom.save(xmlPath)        
        
End   If
    
End Sub

    
private   Function  SecToTime(sec)
        
Dim  h:h  =   " 0 "
        
Dim  m:m  =   " 0 "
        
Dim  s:s  =   " 0 "
        h 
=   round (sec  /   3600 )
        m 
=   round ( (sec  mod   3600 /   60 )
        s 
=   round (sec  mod   60 )
        
If   LEN (h) = 1   Then  h  =   " 0 "   &  h
        
If   LEN (m) = 1   Then  m  =   " 0 "   &  m
        
If   LEN (s) = 1   Then  s  =   " 0 "   &  s
        SecToTime 
=  (h  &   " : "   &  m  &   " : "   &  s)
    
End Function
        
    
private   Function  FormatFileSize(fsize)
        
Dim  radio,k,m,g,unitTMP
        k 
=   1024
        m 
=   1024 * 1024
        g 
=   1024 * 1024 * 1024
        radio 
=   1
        
If   Fix (fsize  /  g)  >   0.0   Then
            unitTMP 
=   " GB "
            radio 
=  g
        
ElseIf   Fix (fsize  /  m)  >   0   Then
            unitTMP 
=   " MB "
            radio 
=  m
        
ElseIf   Fix (fsize  /  k)  >   0   Then
            unitTMP 
=   " KB "
            radio 
=  k
        
Else
            unitTMP 
=   " B "
            radio 
=   1
        
End   If
        
If  radio  =   1   Then
            FormatFileSize 
=  fsize  &   " &nbsp; "   &  unitTMP
        
Else
            FormatFileSize 
=   FormatNumber (fsize / radio, 3 &  unitTMP
        
End   If
    
End Function

    
Private   Sub  Class_Terminate  
      
Set  objDom  =   Nothing
    
End Sub
End  Class
%
>
< script language = " javascript " >
// 启动进度条
function  startProgress(xmlPath){
  displayProgress();
    setProgressDivPos();
    setTimeout(
" DisplayProgressBar(' "   +  xmlPath  +   " ') " , 500 );
}

function  DisplayProgressBar(xmlPath){
    var xmlDoc 
=   new  ActiveXObject( " Msxml2.DOMDocument.3.0 " );
    xmlDoc.async 
=   false ;
    xmlDoc.load(xmlPath);
    
if  (xmlDoc.parseError.errorCode! = 0 ){
        var 
error   =  xmlDoc.parseError;
        alert(
error .reason)
        setTimeout(
" DisplayProgressBar(' "   +  xmlPath  +   " ') " , 1000 );
        return;
    }
    var root 
=  xmlDoc.documentElement;    // 根节点
    var totalbytes 
=  root.childNodes( 0 ).text;
    var uploadbytes 
=  root.childNodes( 1 ).text;
    var percent 
=  root.childNodes( 2 ).text;
    ProgressPercent.innerHTML 
=  percent  +   " % " ;
    ProgressBar.style.width 
=  percent  +   " % " ;
    uploadSize.innerHTML 
=  uploadbytes;
  uploadSpeed.innerHTML 
=  root.childNodes( 3 ).text;
    totalTime.innerHTML 
=  root.childNodes( 4 ).text;
    leftTime.innerHTML 
=  root.childNodes( 5 ).text;
    
if  (percent < 100 ){
      setTimeout(
" DisplayProgressBar(' "   +  xmlPath  +   " ') " , 1000 );
    }
}

function  displayProgress(){
    var objProgress 
=  document.getElementById( " Progress " );
  objProgress.style.display 
=   "" ;
}
function  closeProgress(){
    var objProgress 
=  document.getElementById( " Progress " );
  objProgress.style.display 
=   " none " ;
}
function  setProgressDivPos(){
    var objProgress 
=  document.getElementById( " Progress " );
    objProgress.style.top 
=  document.body.scrollTop + (document.body.clientHeight - document.getElementById( " Progress " ).offsetHeight) / 2
    objProgress.style.left 
=  document.body.scrollLeft + (document.body.clientWidth - document.getElementById( " Progress " ).offsetWidth) / 2 ;
}
</ script >
< style type = " text/css " >
.progress {
    position: absolute;
    padding: 4px;
    top: 
50 ;
    
left 400 ;
    font
- family: Verdana, Helvetica, Arial, sans - serif;
    font
- size: 12px;
    width: 250px;
    height:100px;
    background: #FFFBD1;
    color: #3D2C05;
    border: 1px solid #
715208 ;
    
/*  Mozilla proprietary  */
    
- moz - border - radius: 5px;
    
/*- moz - opacity:  0.95 */
}
.progress table,.progress td{
  font
- size:9pt;
}

.Bar{
  width:
100 %;
    height:15px;
    background
- color:#CCCCCC;
    border: 1px inset #
666666 ;
    margin
- bottom:4px;
}

.ProgressPercent{
    font
- size: 9pt;
    color: #
000000 ;
    height: 15px;
    position: absolute;
    z
- index:  20 ;
    width: 
100 %;
    text
- align: center;
}
.ProgressBar{
  background
- color:#91D65C;
    width:1px;
    height:15px;
}
</ style >
< div id = " Progress "  style = " display:none; "  class = " progress " >
    
< div class = " bar " >
        
< div id = " ProgressPercent "  class = " ProgressPercent " > 0 % </ div >
        
< div id = " ProgressBar "  class = " ProgressBar " ></ div >
    
</ div >
    
< table border = " 0 "  cellspacing = " 0 "  cellpadding = " 2 " >
        
< tr >
            
< td > 已经上传 </ td >
            
< td > : </ td >
            
< td id = " uploadSize " ></ td >
        
</ tr >
        
< tr >
            
< td > 上传速度 </ td >
            
< td > : </ td >
            
< td id = " uploadSpeed " >& nbsp; </ td >
        
</ tr >
        
< tr >
            
< td > 共需时间 </ td >
            
< td > : </ td >
            
< td id = " totalTime " >& nbsp; </ td >
        
</ tr >
        
< tr >
            
< td > 剩余时间 </ td >
            
< td > : </ td >
            
< td id = " leftTime " >& nbsp; </ td >
        
</ tr >
    
</ table >
</ div >


Example.asp代码如下:

 

< %@LANGUAGE = " VBSCRIPT "  CODEPAGE = " 65001 " % >
< ! -- #include file = " SundyUpload.asp " -->
< %
' 此例子文档编码都是UTF-8,如果是其他编码的系统,请将编码转换为相应的编码,不然表单获取数据可能会乱码
Dim  objUpload,opt
Dim  xmlPath
Dim  fileFormName,objFile,counter
opt 
=  request.QueryString( " opt " )
If  opt  =   " Upload "   Then
  xmlPath 
=  Server.MapPath(request.QueryString( " xmlPath " )) ' 将虚拟路径转换为实际路径
     Set  objUpload = new  SundyUpload  ' 建立上传对象
    objUpload.UploadInit xmlPath, " utf-8 "
    counter 
=   1
    Response.Write(
" 普通表单: "   &  objUpload.Form( " normalForm " &   " <BR><BR> " ) ' 获取表单数据
     For   Each  fileFormName In objUpload.objFile
      
Set  objFile = objUpload.objFile(fileFormName)
        fileSize 
=  objFile.FileSize
        fileName 
=  objFile.FileName
        
If  fileSize  >   0   Then
            Response.Write(
" File Size: "   &  fileSize  &   " <BR> " )
            Response.Write(
" File Name: "   &  objFile.FilePath  &  fileName  &   " <BR> " )
            Response.Write(
" File Description: "   &  objUpload.Form( " fileDesc "   &  counter)  &   " <BR><BR> " )
            
' objFile.SaveAs 文件的实际路径(可以自行处理)
         End   If
        counter 
=  counter  +   1
    
Next
    
End   If
' 为上载进度条数据文件(XML文件指定虚拟路径)
'
最好是随机的,因为可能多个人同时上载,需要不同的进度数据
'
这个路径需要在提交的时候传入上载组件中,以便在上载过程中更改进度数据
'
客户端使用Javascript来读取此XML文件,显示进度
xmlPath  =   " upload/ "   &   Timer   &   " .xml "
%
>
< html >
< head >
< meta http - equiv = " Content-Type "  content = " text/html; charset=utf-8 "   />
< title > Sundy Upload Progress Bar Example </ title >
< script language = " javascript " >
function  chkFrm(){
  var objFrm 
=  document.frmUpload;
    
if  (objFrm.file1.value == ""   &&  objFrm.file2.value == "" ){
      alert(
" 请选择一个文件 " );
        objFrm.file1.focus();
        return 
false ;
    }
    objFrm.action 
=   " Example.asp?opt=Upload&xmlPath=<%=xmlPath%> " ;
    startProgress(
' <%=xmlPath%>');//启动进度条
    return  true ;
}
</ script >
</ head >

< body >
< form name = " frmUpload "  method = " post "  action = " Example.asp "  enctype = " multipart/form-data "  onSubmit = " return chkFrm() " >
普通表单:
< BR >< input type = " text "  name = " normalForm "  size = " 40 " >< BR >< BR >
文件1:
< BR >
< input type = " file "  name = " file1 "  size = " 40 " ></ br >
< input type = " text "  name = " fileDesc1 "  size = " 30 " >< BR >< BR >
文件2:
< BR >
< input type = " file "  name = " file2 "  size = " 40 " ></ br >
< input type = " text "  name = " fileDesc2 "  size = " 30 " >< BR >
< input type = " submit "  name = " btnSubmit "  value = " submit " />
</ form >
</ body >
</ html >

将以上代码存为相应的文件,记得这个例子的页面编码一定要是UTF-8的,以后需要自己可以改

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
进度条上传代码,适合学习参考资料,也可直接使用到项目中. 代码片段: Private Sub Class_Initialize() Set Files = Server.CreateObject("Scripting.Dictionary") ' 上传文件集合 Set Form = Server.CreateObject("Scripting.Dictionary") ' 表单集合 UploadProgressInfo = "DoteyUploadProgressInfo" ' Application的Key MaxTotalBytes = 1 *1024 *1024 *1024 ' 默认最大1G ChunkReadSize = 64 * 1024 ' 分块大小64K CrLf = Chr(13) & Chr(10) ' 换行 Set DoteyUpload_SourceData = Server.CreateObject("ADODB.Stream") DoteyUpload_SourceData.Type = 1 ' 二进制流 DoteyUpload_SourceData.Open Version = "1.0 Beta" ' 版本 ErrMsg = "" ' 错误信息 Set Progress = New ProgressInfo End Sub ' 将文件根据其文件名统一保存在某路径下 Public Sub SaveTo(path) Upload() ' 上传 if right(path,1) <> "/" then path = path & "/" ' 遍历所有已上传文件 For Each fileItem In Files.Items fileItem.SaveAs path & fileItem.FileName Next ' 保存结束后更新进度信息 Progress.ReadyState = "complete" '上传结束 UpdateProgressInfo progressID End Sub ' 分析上传的数据,并保存到相应集合中 Public Sub Upload () Dim TotalBytes, Boundary TotalBytes = Request.TotalBytes ' 总大小 If TotalBytes < 1 Then Raise("无数据传入") Exit Sub End If If TotalBytes > MaxTotalBytes Then Raise("您当前上传大小为" & TotalBytes/1000 & " K,最大允许为" & MaxTotalBytes/1024 & "K") Exit Sub End If Boundary = GetBoundary() If IsNull(Boundary) Then Raise("如果form中没有包括multipart/form-data上传是无效的") Exit Sub ''如果form中没有包括multipart/form-data上传是无效的 End If
asp无组件上传类v0.98(无刷新ajax上传,可检查图片木马,支持多文件,utf-8版) 请将本程序放到你的虚拟主机上运行,如果本地有iis也可以。有些同学有简易iis服务器,不适用本程序的,因为有部分中文字符不能识别导致无法运行。 如果需要上传文件可以把index.htm中的multiple="multiple"删除掉,对应的多文件前端显示及处理需要您对upload.asp进行修改调整,然后前端ajax获取数据进行处理。 关于“无组件上传类 Version 0.96”修改摘要: '修改点 : v0.97 修复了一个错误。当用户在同一个file控件选择多个文件上传时file.add语句会出错, 2018-06-04 '   原因是键值冲突,本版本对键值做了唯一化处理。 ' v0.98 将Charset="gb2312" 改成Charset="utf-8",所有文件格式都改成utf8了 2018-8-11 ' 修改了在上传的时候检查图片是否被注入了代码,比如<% 、request 等关键字符 相关参数设置: 1.ajax_upload.asp中的参数设置说明: (1).SavePath 上传目录,默认为“uploadfiles”。 2.clsUpload.asp中的参数设置说明: (1).AllowFiles 所允许上传文件格式,默认为"jpg,jpeg,gif,png"。 (2).MaxDownFileSize 允许上传文件大小,默认30M,注意iis默认限制就几百k,您需要在iis那儿做设置,网站 - asp - 限制属性 - 最大请求实体主体限制,加上两个0,改成20000000,这样就改成20M了。 3.index.htm中的参数说明 在第27和32行,分别是判断类型和大小的,可手动修改。这里是前端检测文件类型和大小的,可减轻服务器工作。后端要等文件post完成才能开始检测,假设误选择了个几百兆的exe、rar等文件网页直接卡死。 提示:在clsUpload.asp的第134行对文件中可能存在的危险asp代码做了简单的检查,具体是判断是否包含“request”字符串,如果需要对其他代码判断可在此处修改。建议不要以判断<%、eval、%>这3个特殊字符串来确定图片木马,因为正常文件中可能也有,而且有些图马文件没有<%。 如果需要测试图片木马文件可以自己百度制作方法,按照教程做几个图片木马文件然后用本程序上传测试。 本程序由sysdzw提供。如有需技术支持可联系QQ:171977759 09:02 2018-08-13
参考:https://blog.csdn.net/sysdzw/article/details/80562058 微标ASP上传类 v1.3(无刷新、无组件、多文件上传,并且可查杀木马,utf-8格式) 请将本程序放到你的虚拟主机上运行,如果本地有iis也可以(注意定要把iis那儿的上传大小限制的200k改大点,参考下面第二点)。注意不要使用一些简易asp服务器,会有莫名其妙的错误。 如果只需要上传文件可以把index.htm中的multiple="multiple"删除掉,对应的多文件前端显示及处理需要您对upload.asp进行修改调整,然后前端ajax获取数据进行处理。 关于“微标ASP上传类 v1.3”更新摘要: '========================================================================================================= '类 名 : 微标ASP上传类 v1.3(无刷新、无组件、多文件上传,并且可查杀木马,utf-8格式) '作 者 : sysdzw '联系QQ : 171977759 '网 站 : https://blog.csdn.net/sysdzw '版 本 : v1.0 以化境ASP无组件上传作为初版v1.0, 之后进行了多项修改。 ' v1.1 修正了批量上传时file.add语句的报错问题。原因是键值冲突,本版本对键值做了唯一化处理。 2018-06-04 ' v1.2 修改文件格式为utf-8格式,以提高兼容性 2018-08-13 ' 修改代码中部分Charset="gb2312"为Charset="utf-8",以提高兼容性 ' 增加了图片木马检测功能。在上传的时候以gb2312格式读入字符串检测是否包含request等关键字 ' v1.3 改进了图片木马检测功能。加入了更多的关键字判断,让木马无处遁形 2018-10-04 '========================================================================================================= 相关参数设置: 1.ajax_upload.asp中的参数设置说明: (1)SavePath 上传目录,默认为“uploadfiles”。 2.clsUpload.asp中的参数设置说明: (1)AllowFiles 所允许上传文件格式,默认为"jpg,jpeg,gif,png"。 (2)MaxDownFileSize 允许上传文件大小,默认30M,注意iis默认限制就200k,您需要在iis那儿做设置,网站 - asp - 限制属性 - 最大请求实体主体限制,加上两个0,改成20000000,这样就改成20M了。 3.index.htm中的参数说明 在第32和37行,分别是判断类型和大小的,可根据需要修改。这里是前端检测文件类型和大小的,可减轻服务器工作。后端要等文件post完成才能开始检测,假设误选择了个几百兆的exe、rar等文件网页直接卡死。早发现文件早提示。 查杀图片木马原理:一些图片会被不法分子插入些可执行的asp代码,在被include的时候悄悄执行,我们将图片以文本方式进行检查,判断是否包含某些关键字,如果包含就停止上传,总而提高了服务器的安全。 本来想打包个图片木马文件供大家测试,担心上传会不通过,而且下载了后本机的360等软件也会报毒,这样会吓坏一批小白,以为我代码有什么后门。。其实就那么几行代码,大家可以逐行看,没什么机关的。如果一定想试验下代码的效果可以百度下asp图片木马制作方法,然后自己做个图马上传测试看看。 本程序由sysdzw提供。如有需技术支持可联系QQ:171977759

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值