<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
<! -- # Include file = "SundyUpload. asp" -->
<%
\ 'This example document encoding is a UTF-8, if it is another encoding system, please convert the encoding to the corresponding encoding, otherwise the form to get data may be garbled
Dim objUpload, opt
Dim xmlPath
Dim fileFormName, objFile, counter
Opt = request. QueryString ("opt ")
If opt = "Upload" Then
XmlPath = Server. MapPath (request. QueryString ("xmlPath") \ 'converts the virtual path to the actual path
Set objUpload = new SundyUpload \ 'to create an upload object
ObjUpload. UploadInit xmlPath, "UTF-8"
Counter = 1
Response. Write ("normal Form:" & objUpload. Form ("normalForm") & "<BR>") \ 'Get Form data
For Each fileFormName In objUpload. objFile
Set objFile = objUpload. objFile (fileFormName)
FileSize = objFile. FileSize
StrTemp = objFile. FilePath
Response. Write strTemp
FileName = mid (strTemp, limit Rev (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> ")
ObjFile. SaveAs Server. MapPath (".") & "\ upload \" & fileName
Response. Write "Save at:" & Server. MapPath (".") & "\ upload \" & fileName & "<br>"
End If
Counter = counter + 1
Next
End If
\ 'Indicates the upload progress bar Data File (virtual path specified for the XML file)
\ 'Should be random, because multiple people may upload at the same time and different progress data is required.
\ 'This path must be passed into the upload component at the time of submission to change the progress data during the upload process.
\ 'The client uses javascript to read the XML file and displays the progress.
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 ("Select a file ");
ObjFrm. file1.focus ();
Return false;
}
ObjFrm. action = "Example. asp? Opt = Upload & xmlPath = <% = xmlPath %> ";
StartProgress (\ '<% = xmlPath %> \'); // progress bar
Return true;
}
</Script>
</Head>
<Body>
<Form name = "frmUpload" method = "post" action = "Example. asp" enctype = "multipart/form-data" onSubmit = "return chkFrm ()">
Normal form: <BR> <input type = "text" name = "normalForm" size = "40"> <BR>
File 1: <BR>
<Input type = "file" name = "file1" size = "40"> </br>
<Input type = "text" name = "fileDesc1" size = "30"> <BR>
File 2: <BR>
<Input type = "file" name = "file2" size = "40"> </br>
<Input type = "text" name = "fileDesc2" size = "30"> <BR>
File 3: <BR>
<Input type = "file" name = "file3" size = "40"> </br>
File 4: <BR>
<Input type = "file" name = "file4" size = "40"> </br>
File 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 \ 'total size
ChunkReadSize = 64*1024 \ 'block size 64 K
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
\ 'Multipart read
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, Region B (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