今天在網(wǎng)上看到這個(gè)asp上傳帶進(jìn)度條的程序,試了一下,效果不錯(cuò),現(xiàn)在放到這里來(lái)與大家共享。
<!--#include file="SundyUpload.asp"-->
< %
'此例子文檔編碼都是UTF-8,如果是其他編碼的系統(tǒng),請(qǐng)將編碼轉(zhuǎn)換為相應(yīng)的編碼,不然表單獲取數(shù)據(jù)可能會(huì)亂碼
Dim objUpload,opt
Dim xmlPath
Dim fileFormName,objFile,counter
opt = request.QueryString("opt")
If opt = "Upload" Then
xmlPath = Server.MapPath(request.QueryString("xmlPath"))'將虛擬路徑轉(zhuǎn)換為實(shí)際路徑
Set objUpload=new SundyUpload '建立上傳對(duì)象
objUpload.UploadInit xmlPath,"utf-8"
counter = 1
Response.Write("普通表單:" & objUpload.Form("normalForm") & "<BR><BR>")'獲取表單數(shù)據(jù)
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
'為上載進(jìn)度條數(shù)據(jù)文件(XML文件指定虛擬路徑)
'最好是隨機(jī)的,因?yàn)榭赡芏鄠€(gè)人同時(shí)上載,需要不同的進(jìn)度數(shù)據(jù)
'這個(gè)路徑需要在提交的時(shí)候傳入上載組件中,以便在上載過(guò)程中更改進(jìn)度數(shù)據(jù)
'客戶端使用Javascript來(lái)讀取此XML文件,顯示進(jìn)度
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("請(qǐng)選擇一個(gè)文件");
objFrm.file1.focus();
return false;
}
objFrm.action = "Example.asp?opt=Upload&xmlPath=<%=xmlPath%>";
startProgress('<%=xmlPath%>');//啟動(dòng)進(jìn)度條
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>
新聞熱點(diǎn)
疑難解答
圖片精選