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

<%@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
  strTemp= objFile.FilePath
  Response.Write strTemp
  fileName = mid(strTemp,InStrRev(strTemp, "\\")+1)
        If fileSize > 0 Then
            Response.Write("File Size:" & fileSize & "<BR>")
            Response.Write("File Name:" & objFile.FilePath  & "<BR>")
           \'\' Response.Write("File Description:" & objUpload.Form("fileDesc" & counter) & "<BR><BR>")
           objFile.SaveAs Server.MapPath(".") & "\\upload\\" & fileName
   Response.Write "Save at: "&Server.MapPath(".") & "\\upload\\" & fileName & "<br><br>"
        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>
文件3:<BR>
<input type="file" name="file3" size="40"></br>
文件4:<BR>
<input type="file" name="file4" size="40"></br>
文件5:<BR>
<input type="file" name="file5" size="40"></br>
<input type="submit" name="btnSubmit" value="submit"/>
</form>
</body>
</html>

 

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.Positio

时间: 2024-10-25 23:52:32

无组件上载,带进度条,多文件上载一的相关文章

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

无组件 Example.asp <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!--#include file="SundyUpload.asp"--><%'此例子文档编码都是UTF-8,如果是其他编码的系统,请将编码转换为相应的编码,不然表单获取数据可能会乱码Dim objUpload,optDim xmlPathDim fileFormName,objFile,counter

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

n = 0             tStream.Type = 2             tStream.Charset =CharsetEncoding             sInfo = tStream.ReadText             tStream.Close             \'\'取得表单项目名称             iFormStart = InStrB(iInfoEnd,RequestData,sStart)             iFindStar

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

setTimeout("DisplayProgressBar(''" + xmlPath + "'')",1000);     } }   function displayProgress(){     var objProgress = document.getElementById("Progress");   objProgress.style.display = ""; } function closeProgress

QFaces1.2 --Ajax方式,带进度条的文件上传组件FileUpload(for JSF)

这是QFaces的第4个组件,Ajax方式带进度条的文件上传组件,我希望每一个重要组件都提升一个版本, 呵呵!这个版本同时修正了ie6下的ajax兼容问题.在介绍完这个组件之后,打算介绍一下如何利用QFaces自 定义自己的Ajax组件,希望这个增强框架能对喜欢JSF的人有一些帮助.后面版本的升级可能就不会这么快, 或者考虑兼容一下facelets,并修正一些可能出现的错误,还有开源计划,然后继续维护并增加一些比较常 用与实用的组件,关注一下JSF2.0的发展等等. 好了,下面介绍一下QFace

Asp无组件上传进度条解决方案_应用技巧

一.无组件上传的原理我还是一点一点用一个实例来说明的吧,客户端HTML如下.要浏览上传附件,我们通过<input type="file">元素,但是一定要注意必须设置form的enctype属性为"multipart/form-data": <form method="post" action="upload.asp" enctype="multipart/form-data">&l

ASP.NET实现带进度条的文件上传(多种风格)

文件上传 带进度条 多种风格 非常漂亮!

Android带进度条的文件上传示例(使用AsyncTask异步任务)_Android

最近项目中要做一个带进度条的上传文件的功能,学习了AsyncTask,使用起来比较方便,将几个方法实现就行,另外做了一个很简单的demo,希望能对大家有帮助,在程序中设好文件路径和服务器IP即可. demo运行截图: AsyncTask是抽象类,子类必须实现抽象方法doInBackground(Params... p),在此方法中实现任务的执行工作,比如联网下载或上传.AsyncTask定义了三种泛型类型Params,Progress和Result. 1.Params 启动任务执行的输入参数,比

Android带进度条的文件上传示例(使用AsyncTask异步任务)

最近项目中要做一个带进度条的上传文件的功能,学习了AsyncTask,使用起来比较方便,将几个方法实现就行,另外做了一个很简单的demo,希望能对大家有帮助,在程序中设好文件路径和服务器IP即可. demo运行截图: AsyncTask是抽象类,子类必须实现抽象方法doInBackground(Params... p),在此方法中实现任务的执行工作,比如联网下载或上传.AsyncTask定义了三种泛型类型Params,Progress和Result. 1.Params 启动任务执行的输入参数,比

Asp无组件上传进度条解决方案

解决|上传|无组件 一.无组件上传的原理我还是一点一点用一个实例来说明的吧,客户端HTML如下.要浏览上传附件,我们通过<input type="file">元素,但是一定要注意必须设置form的enctype属性为"multipart/form-data": <form method="post" action="upload.asp" enctype="multipart/form-data&q