<html><title>example</title>
<body>
<!--#include FILE="upload_5xsoft.inc"-->
<%
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>0 then
file.saveAs Server.mappath("temp.jpg")
response.write "<br>上传文件:"&file.FileName&" => temp.jpg OK!"
response.write "<br>文件大小:"&file.FileSize
set file=nothing
end if
set upload=nothing
%></body>
</html>
2.列表出有文件表单(多文件上传)
<html><title>example</title>
<body>
<!--#include FILE="upload_5xsoft.inc"-->
<%
set upload=new upload_5xsoft
for each formName in upload.file
set file=upload.file(formName)
if file.FileSize>0 then
file.SaveAs Server.mappath(file.FileName)
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "
response.write file.FileName&" 成功!<br>"
end if
set file=nothing
next
set upload=nothing
%>
<html><title>example</title>
<body>
<!--#include FILE="upload_5xsoft.inc"-->
<%
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>0 then
file.saveAs Server.mappath("temp.jpg")
response.write "<br>上传文件:"&file.FileName&" => temp.jpg OK!"
response.write "<br>文件大小:"&file.FileSize
set file=nothing
end if
set upload=nothing
%></body>
</html>
2.列表出有文件表单(多文件上传)
<html><title>example</title>
<body>
<!--#include FILE="upload_5xsoft.inc"-->
<%
set upload=new upload_5xsoft
for each formName in upload.file
set file=upload.file(formName)
if file.FileSize>0 then
file.SaveAs Server.mappath(file.FileName)
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "
response.write file.FileName&" 成功!<br>"
end if
set file=nothing
next
set upload=nothing
%>
<DIV align="left">
<FORM METHOD="POST" ACTION="upload.asp" ENCTYPE="multipart/form-data"name="frmfile" target="_blank">
<FIELDSET><LEGEND><font color="#FFFFFF">試題相關媒體文件上傳</font></LEGEND>
<UL>
<LI><font color="#FFFFFF">歡迎使用檔案(文件)上傳服務﹐您可以上傳多個檔案(文件) </font>
<LI><font color="#FFFFFF">注意﹐本上傳軟件不支持中文﹐所以檔案(文件名)名稱不能含有中文﹐否則會產生錯誤。 </font>
<LI><font color="#FFFFFF">上傳文件的類型﹕
<input type="radio" value="a" checked name="R1" onclick="getimg()">
圖片
<input type="radio" name="R1" value="b" onclick="getvideo()">
視頻文件
<input type="radio" name="R1" value="c" onclick="getsound()">
聲音文件 </font>
</UL>
<P align="center"><font color="#FFFFFF">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50">
<BR>
<INPUT TYPE="button" VALUE="開始上傳文件" onclick="chfile()">
</font><br>
<input type="hidden" name="filepath" size="20">
<input type="hidden" name="uptype" size="20" value="a">
<input type="hidden" name="typelist" size="20"value="">
</FIELDSET>
</FORM>
</DIV>
</body>
</html>
<script language=vbscript>
<!--
'******************************************
'函數名﹕gtfilename 參數類型﹕string
'作用﹕將從包含文件名的路徑中將文件名提
'取出來
'編寫時間﹕2001.11.12
'******************************************
function gtfilename(string1)
string1=trim(string1)
str_len=len(string1)
if string1<>empty then
s1=instr(string1,"\")
string1=mid(string1,s1+1,str_len-s1)
if instr(string1,"\")=0 then
gtfilename=string1
else
gtfilename=gtfilename(string1)
end if
end if
end function
sub getimg()
frmfile.uptype.value="a"
end sub
sub getvideo()
frmfile.uptype.value="b"
end sub
sub getsound()
frmfile.uptype.value="c"
end sub
sub chfile()
if frmfile.file1.value=empty then
window.alert "請選擇你要上載的文件﹗"
exit sub
else
if frmfile.filepath.value=empty then
frmfile.filepath.value=gtfilename(frmfile.file1.value)
else
frmfile.filepath.value=gtfilename(frmfile.file1.value)
end if
extname=right(trim(frmfile.file1.value),3)
extname=lcase(extname)
if extname="asp" then
window.alert "對不起﹗不能上傳擴展名為asp的文件﹗"
exit sub
end if
if extname="php" then
window.alert "對不起﹗不能上傳擴展名為php的文件﹗"
exit sub
end if
if extname="jsp" then
window.alert "對不起﹗不能上傳擴展名為jsp的文件﹗"
exit sub
end if
if extname="exe" then
window.alert "對不起﹗不能上傳擴展名為exe的文件﹗"
exit sub
end if
if extname="com" then
window.alert "對不起﹗不能上傳擴展名為com的文件﹗"
exit sub
end if
if extname="eml" then
window.alert "對不起﹗不能上傳擴展名為eml的文件﹗"
exit sub
end if
if extname="cih" then
window.alert "對不起﹗不能上傳擴展名為CIH的文件﹗"
exit sub
end if
if frmfile.uptype.value="a" then
if instr("gif#jpg#bmp#ico#",extname)=0 then
window.alert "對不起﹗你上傳的不是圖片文件﹗"
exit sub
end if
end if
if frmfile.uptype.value="b" then
if instr("avi#wmv#mpeg#mpg#m1v#wma#asf#",extname)=0 then
window.alert "對不起﹗你上傳的不是視頻文件﹗"
exit sub
end if
end if
if frmfile.uptype.value="c" then
if instr("mid#midi#rmi#wav#snd#au#mp3",extname)=0 then
window.alert "對不起﹗你上傳的不是聲音文件﹗"
exit sub
end if
end if
if frmfile.typelist.value=empty then
frmfile.typelist.value=frmfile.uptype.value
else
frmfile.typelist.value=frmfile.uptype.value
end if
frmfile.submit
end if
end sub
-->
</script>
第2个文件
upload.asp
<%
Dim objUpload
Dim FileCount
'建立 AspSmartUpload 對象
Set objUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
'使用 AspSmartUpload 對象的 Upload 方法﹐取得表單送出來的數據
objUpload.Upload
upfilename=objUpload.files.item(1).filename
%>
<!--#include file="test_upload.asp"-->
<%
'將文件以原文件名存入指定的虛擬路徑中﹐並將上傳的文件數存入 FileCount 變量中
FileCount = objUpload.Save("Upload Files")
Filename=objUpload.files.item(1).filename
Flieext=objUpload.files.item(1).fileext
Filesize=objUpload.files.item(1).size
appath1="Upload Files/"&Filename
flag1=objUpload.Form("R1").values
'將文件列表寫入session變量
if session("upfile_name_list")="" and session("upfile_type_list")="" then
session("upfile_name_list")=objUpload.Form("filepath").values
session("upfile_type_list")=objUpload.Form("typelist").values
else
session("upfile_name_list")=session("upfile_name_list")&"#"&objUpload.Form("filepath").values
session("upfile_type_list")=session("upfile_type_list")&"#"& objUpload.Form("typelist").values
end if
k1=session("upfile_name_list")
k2= session("upfile_type_list")
response.write k1&"<br>"
response.write k2&"<br>"
if flag1="a" then
type1="圖形文件"
end if
if flag1="b" then
type1="視頻文件"
end if
if flag1="c" then
type1="聲音文件"
end if