<%@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) 'g0= f0=replace(replace(replace(now(),":","")," ",""),"-","")&"."&g0 If fileSize > 0 Then Response.Write("File Size:" & fileSize & "<BR>") Response.Write("File Name:" & objFile.FilePath & "<BR>") t=Split(filename,".") t1=t(1) filename=Replace(Replace(Replace(now,":","")," ",""),"-","")&"."&t1 ' 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>
example.aspjavascript