今天在網上看到這個asp上傳帶進度條的程序,試了一下,效果不錯,現在放到這裡來與大家共享。
<!--#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>