利用SA FileUp組件進(jìn)行多文件上傳
更新時(shí)間:2007年01月03日 00:00:00 作者:
大家可以根據(jù)自己的實(shí)際情況進(jìn)行修改,特別是數(shù)據(jù)庫(kù)操作部分。
============================================
利用稻香老農(nóng)的無組件進(jìn)行多文件上傳
請(qǐng)見:
http://bbs.blueidea.com/viewthread.php?tid=1249535
==================================================
本例屬于文件和表單項(xiàng)的混合提交。
簡(jiǎn)單說明:
雖然重點(diǎn)在處理頁(yè)上,但我覺得有必要介紹一下表單的項(xiàng)目。
本例是相冊(cè)里像片的上傳。
其中的groupID是隱藏域傳遞的大類的ID
其中的albumID是隱藏域傳遞的小類的ID
file1-->>file5是文件
photoTitle1-->>photoTitle5 是像片的標(biāo)題
photoIntro1-->>photoIntro5 是像片的簡(jiǎn)介
photoWidth1-->>photoWidth5 是像片的寬度
photoHeight1-->>photoHeigth5 是像片的高度
photoSize1-->>photoSize5 是像片的大小。
注意:因本人沒有聲明變量的習(xí)慣,所以大家要是強(qiáng)制聲明變量的話,就得自己加了。
===========================================
提交頁(yè):主要代碼如下
<form name="fileForm" method="post" action="photo_savephoto.asp" enctype="multipart/form-data" onSubmit="return checkForm();">
<INPUT name="groupID" type="hidden" id="groupID" value="<%=groupID%>" size="10">
<INPUT name="albumID" type="hidden" id="albumID" value="<%=albumID%>" size="10">
上傳說明:最多可以同時(shí)上傳五個(gè)文件,其中標(biāo)題最多30字,簡(jiǎn)介200字。
<table width="96%" align="center" cellpadding="4" cellspacing="2">
<tr align="center" valign="middle">
<td align="left" bgcolor="#F4CECE" id="upid">文件1</td>
<td height="29" align="left" bgcolor="#F4CECE" id="upid"> <INPUT name="file1" type="file" class="myInput" size="20">
寬: <INPUT name="photoWidth1" type="text" class="input-disabled" id="photoWidth1" size="5" readonly="">
高: <INPUT name="photoHeight1" type="text" class="input-disabled" id="photoHeight1" size="5" readonly="">
大?。?lt;INPUT name="fileSize1" type="text" class="input-disabled" id="fileSize1" size="5" readonly="">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2" align="left" bgcolor="#FDF2F2" id="upid">
標(biāo)題: <INPUT name="photoTitle1" type="text" class="myInput" id="photoTitle1" size="40">
<BR>
簡(jiǎn)介:<TEXTAREA name="photoIntro1" cols="60" rows="5" class="myInput" id="photoIntro1"></TEXTAREA>
</td>
</tr>
。。。。。。。
<tr align="center" valign="middle" bgcolor="#F4CECE">
<td height="24" colspan="2">
<input name="Submit" type="submit" class="myButton" value="開始上傳">
<input name="Submit2" type="reset" class="myButton" value="重新填寫">
</td>
</tr>
</table>
</form>
下面的script是我用來檢查圖片屬性的。其中檢查了圖片的寬度,高度,大小,是否是圖片。
<SCRIPT language="JavaScript">
<!--
var upFileSize=<%=upFileSize%>;
//-->
</SCRIPT>
<SCRIPT language="JavaScript" src="photo_addphoto.js"></SCRIPT>
<TABLE width="98%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<TR>
<TD height="1"><img src="images/add.gif" id="loadPhoto" onload="if(!firstLoad)showInfo();"></TD>
</TR>
</TABLE>
photo_addphoto.js
提示:您可以先修改部分代碼再運(yùn)行===============
這里只寫出了一個(gè)文件的相關(guān)輸入框,其他四個(gè)類似。
說明一點(diǎn),并不是有5 個(gè)的限制,只是我這里只寫了5個(gè)。
其中的photo_addphoto.js在客戶端對(duì)圖片進(jìn)行一遍檢查,不是圖片的會(huì)提示,大小超過限制的也會(huì)提示。
這樣就避免了用戶經(jīng)過耐心的等待后才被告訴不合標(biāo)準(zhǔn)的煩惱。
=================================================
處理頁(yè)代碼:
<%@ CODEPAGE="936"%>
<%
Server.ScriptTimeOut=5000 '--腳本超時(shí)設(shè)置為5000
%>
<!--#include file="conn.asp" -->
<%
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") '--建立SA FileUp Object
'oFileUp.Path = Server.MapPath("/upfile/") '--我這里要自己定義文件名,所以沒有使用Path屬性,注意這句被注釋掉了。
strRestrictBy = "" '--文件驗(yàn)證方式,分為extension和ContentType
iCount=0 '--文件上傳數(shù)的計(jì)數(shù)變量
formPath="upfile/" '文件保存位置
'-----------檢查是否有在此位置上傳的權(quán)限-----------這里省略了。
groupID=trim(oFileUp.form("groupID"))
albumID=trim(oFileUp.form("albumID"))
'-----------檢查權(quán)限完成------
if errMsg="" then '----如果到此還沒有錯(cuò)誤
For Each strFormElement In oFileUp.Form
If IsObject(oFileUp.Form(strFormElement)) Then '如果是文件
If Not oFileUp.Form(strFormElement).IsEmpty Then '--文件不為空
flagOK=1
'--不是文件或文件大于限制,設(shè)置錯(cuò)誤信息
If oFileUp.Form(strFormElement).TotalBytes<100 Then
flagOK=0
ElseIf oFileUp.Form(strFormElement).TotalBytes> upFileSize Then
flagOK=0
errMsg=errMsg+"文件:"&oFileUp.Form(strFormElement).UserFileName&" 大于"&upFileSize\1024&"KB!<br>"
Else
strShortFileName = mid(oFileUp.Form(strFormElement).UserFileName,InStrRev(oFileUp.Form(strFormElement).UserFileName, "\")+1) '取得文件名
strExtension = Mid(strShortFileName, InStrRev(strShortFileName, ".")) '取得擴(kuò)展名
If strRestrictBy = "extension" Then '--驗(yàn)證方式為擴(kuò)展名
'strShortFileName = oFileUp.Form(strFormElement).ShortFileName
'======檢查后綴名====
Select Case LCase(strExtension)
Case ".jpg", ".gif", ".bmp",".png"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>錯(cuò)誤:</B> 擴(kuò)展名為 <I>" & strExtension & "</I> 的文件不能被上傳。<BR>")
End Select
Else '--驗(yàn)證方式為MIME類型
strContentType = oFileUp.Form(strFormElement).ContentType
Select Case LCase(strContentType)
Case "image/gif", "image/jpeg", "image/pjpeg"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>錯(cuò)誤:</B> MIME類型為 <I>" & strContentType & "</I> 的文件不能被上傳。<BR>")
End Select
End If '--end if 驗(yàn)證方式
End If 'end if 文件大小判斷
If flagOK=1 Then '如果文件通過檢查,保存文件,并插入數(shù)據(jù)庫(kù)紀(jì)錄
randomize
ranNum=int(900*rnd)+100
filename=year(now())&month(now())&day(now())&hour(now())&minute(now())&second(now())&ranNum&LCase(strExtension)
oFileUp.Form(strFormElement).SaveInVirtual formPath&filename '讓文件名不重復(fù),保存文件,這里用的是SaveInVirtual方法
'--輸出服務(wù)器上的文件路徑
Response.Write oFileUp.Form(strFormElement).ServerName & ":ServerName<BR>"
'--輸出客戶端的文件路徑
Response.Write "<BR><B>文件:</B>"&oFileUp.Form(strFormElement).UserFileName & "<BR>"
'--輸出該文件的大小
Response.Write "<B>大?。?lt;/B>"&oFileUp.Form(strFormElement).TotalBytes & "<BR>"
'===添加文件的信息到數(shù)據(jù)庫(kù)里===
myIndex=right(strFormElement,1) '--取得文件的序號(hào),如file1則取得為1,file2取得為2
temp_photoTitle=oFileUp.form("photoTitle"+myIndex) '--這四行取得對(duì)應(yīng)的標(biāo)題,簡(jiǎn)介,寬度,高度
temp_photoIntro=oFileUp.form("photoIntro"+myIndex)
temp_photoWidth=oFileUp.form("photoWidth"+myIndex)
temp_photoHeight=oFileUp.form("photoHeight"+myIndex)
'====檢查輸入,為空則給初值==
temp_photoTitle=replace(trim(temp_photoTitle),"'","''")
if temp_photoTitle="" then
temp_photoTitle="沒有填寫"
end if
temp_photoIntro=replace(trim(temp_photoIntro),"'","''")
if temp_photoIntro="" then
temp_photoIntro="沒有填寫"
end if
if temp_photoWidth="" or not IsNumeric(temp_photoWidth) then
temp_photoWidth=160
end if
if temp_photoHeight="" or not IsNumeric(temp_photoHeight) then
temp_photoHeight=120
end if
'===插入數(shù)據(jù)庫(kù)===
FileSize=oFileUp.Form(strFormElement).TotalBytes
sql="insert into TBL_PHOTO(albumID,groupID,userName,addTime,photoFilename,photoTitle,photoIntro,photoClick,photoSize,photoWidth,photoHeight,locked,viewPassword) values("&albumID&","&groupID&",'"&session("userName")&"','"&Now()&"','"&filename&"','"&temp_photoTitle&"','"&temp_photoIntro&"',1,"&FileSize&","&temp_photoWidth&","&temp_photoHeight&",'no','')"
conn.execute sql
sql="update TBL_ALBUM set photoCount=photoCount+1 where albumID="&albumID
conn.execute sql
sql="update TBL_GROUP set photoCount=photoCount+1 where groupID="&groupID
conn.execute sql
'===輸出上傳成功信息===
iCount=iCount+1
End If
Else
Response.Write strFormElement & "對(duì)象為空!"
End If '--end if 對(duì)象為空
End If '--end if 是否是文件
Next
Set oFileUp = Nothing '刪除此對(duì)象
end if '--end if 沒有錯(cuò)誤信息
response.write "<br>"&iCount&" 個(gè)文件上傳結(jié)束!"
response.write "<br><a href='photo_listphoto.asp?albumID="&albumID&"'><B>返回相冊(cè)</B></a>"
'=====如果有錯(cuò),輸出錯(cuò)誤信息=====
if errMsg<>"" then
response.write "<br>"&errMsg
response.write "<INPUT type='button' onClick='history.go(-1)' value='返回' class='myInput'>"
end if
conn.close
set conn=nothing
%>
===================================================
看完了實(shí)例,下面對(duì)SA FileUP的屬性和方法進(jìn)行簡(jiǎn)單的介紹,免得大家初次接觸感到發(fā)暈。
這些是我覺得比較常用的,例句和注釋都是按我的理解寫的。
如果大家在應(yīng)用中發(fā)現(xiàn)有什么問題,請(qǐng)指出。謝謝。
建立SA FileUp 對(duì)象的方法:
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
取出表單所有項(xiàng)的方法:
For Each strFormElement In oFileUp.Form
用 oFileUp.Form(strFormElement)就可以引用每個(gè)對(duì)象,文件也是這樣
注意:如果是多選下拉框,則用oFileUp.FormEx(strFormElement)
可以這樣來遍歷它。
For Each strSubItem In oFileUp.FormEx(strFormElement)
Response.Write( strSubItem & "<BR>")
Next
Next
ContentType屬性:
oFileUp.Form(strFormElement).ContentType
可以得到文件的MIME類型
IsEmpty屬性
oFileUp.Form(strFormElement).IsEmpty
可以知道用戶是不是指定了一個(gè)無效的文件
MaxBytes屬性
oFileUp.Form(strFormElement).MaxBytes=30000
指定文件的限制,單位為Byte,如果超過它,那么只存儲(chǔ)MaxBytes指定的大小。其余舍棄。
ServerName屬性
oFileUp.Form(strFormElement).ServerName
可以得到文件保存到服務(wù)器的完整路徑。
ShortFilename屬性
oFileUp.Form(strFormElement).ShortFilename
可以得到客戶端的文件名,注意只是文件名,我這里沒有用,因?yàn)閳?bào)錯(cuò)。呵呵。
UserFilename屬性
oFileUp.Form(strFormElement).UserFileName
可以得到客戶端文件的完整路徑??梢暂敵鲆幌陆o用戶看看。
TotalBytes屬性
oFileUp.Form(strFormElement).TotalBytes
可以得到文件的大小,單位為Byte
SaveInVirtual(路徑)方法
oFileUp.Form(strFormElement).SaveInVirtual "upfile/"
oFileUp.Form(strFormElement).SaveInVirtual "upfile/aa.abc"
如果只指定了路徑,則保留原文件名,否則按指定指定文件名保存
服務(wù)器管理員可以禁止掉其他所有方法,但這個(gè)一定會(huì)留的。
SaveAs (文件名)方法
oFileUp.Form(strFormElement).SaveAs "C:\aa\a.tmp"
如果沒有指定路徑,只是指定了文件名,那么將用Path屬性指定的路徑。
Path屬性一會(huì)介紹。
Save方法
oFileUp.Path="D:\wwwroot\abc\upfile\"
注意必須是真實(shí)路徑,可以用Server.MapPath來轉(zhuǎn)換虛擬路徑。
oFileUp.Form(strFormElement).Save
不能指定文件名嘍。
注意:Path屬性必須在提到任何表單項(xiàng)之前,建議放在
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
的后面。前提是你用的話。
Delete (文件名,可選)
oFileUp.Form(strFormElement).Delete
從服務(wù)器上刪除文件,如果不指定文件名,則刪除當(dāng)前的文件。
如果指定的話,必須是文件的完整路徑。
Flush方法
oFileUp.Flush
當(dāng)你不想保存任何東西的時(shí)候,可以用它來放棄全部的輸入流。
============================================
利用稻香老農(nóng)的無組件進(jìn)行多文件上傳
請(qǐng)見:
http://bbs.blueidea.com/viewthread.php?tid=1249535
==================================================
本例屬于文件和表單項(xiàng)的混合提交。
簡(jiǎn)單說明:
雖然重點(diǎn)在處理頁(yè)上,但我覺得有必要介紹一下表單的項(xiàng)目。
本例是相冊(cè)里像片的上傳。
其中的groupID是隱藏域傳遞的大類的ID
其中的albumID是隱藏域傳遞的小類的ID
file1-->>file5是文件
photoTitle1-->>photoTitle5 是像片的標(biāo)題
photoIntro1-->>photoIntro5 是像片的簡(jiǎn)介
photoWidth1-->>photoWidth5 是像片的寬度
photoHeight1-->>photoHeigth5 是像片的高度
photoSize1-->>photoSize5 是像片的大小。
注意:因本人沒有聲明變量的習(xí)慣,所以大家要是強(qiáng)制聲明變量的話,就得自己加了。
===========================================
提交頁(yè):主要代碼如下
<form name="fileForm" method="post" action="photo_savephoto.asp" enctype="multipart/form-data" onSubmit="return checkForm();">
<INPUT name="groupID" type="hidden" id="groupID" value="<%=groupID%>" size="10">
<INPUT name="albumID" type="hidden" id="albumID" value="<%=albumID%>" size="10">
上傳說明:最多可以同時(shí)上傳五個(gè)文件,其中標(biāo)題最多30字,簡(jiǎn)介200字。
<table width="96%" align="center" cellpadding="4" cellspacing="2">
<tr align="center" valign="middle">
<td align="left" bgcolor="#F4CECE" id="upid">文件1</td>
<td height="29" align="left" bgcolor="#F4CECE" id="upid"> <INPUT name="file1" type="file" class="myInput" size="20">
寬: <INPUT name="photoWidth1" type="text" class="input-disabled" id="photoWidth1" size="5" readonly="">
高: <INPUT name="photoHeight1" type="text" class="input-disabled" id="photoHeight1" size="5" readonly="">
大?。?lt;INPUT name="fileSize1" type="text" class="input-disabled" id="fileSize1" size="5" readonly="">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2" align="left" bgcolor="#FDF2F2" id="upid">
標(biāo)題: <INPUT name="photoTitle1" type="text" class="myInput" id="photoTitle1" size="40">
<BR>
簡(jiǎn)介:<TEXTAREA name="photoIntro1" cols="60" rows="5" class="myInput" id="photoIntro1"></TEXTAREA>
</td>
</tr>
。。。。。。。
<tr align="center" valign="middle" bgcolor="#F4CECE">
<td height="24" colspan="2">
<input name="Submit" type="submit" class="myButton" value="開始上傳">
<input name="Submit2" type="reset" class="myButton" value="重新填寫">
</td>
</tr>
</table>
</form>
下面的script是我用來檢查圖片屬性的。其中檢查了圖片的寬度,高度,大小,是否是圖片。
<SCRIPT language="JavaScript">
<!--
var upFileSize=<%=upFileSize%>;
//-->
</SCRIPT>
<SCRIPT language="JavaScript" src="photo_addphoto.js"></SCRIPT>
<TABLE width="98%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<TR>
<TD height="1"><img src="images/add.gif" id="loadPhoto" onload="if(!firstLoad)showInfo();"></TD>
</TR>
</TABLE>
photo_addphoto.js
提示:您可以先修改部分代碼再運(yùn)行
這里只寫出了一個(gè)文件的相關(guān)輸入框,其他四個(gè)類似。
說明一點(diǎn),并不是有5 個(gè)的限制,只是我這里只寫了5個(gè)。
其中的photo_addphoto.js在客戶端對(duì)圖片進(jìn)行一遍檢查,不是圖片的會(huì)提示,大小超過限制的也會(huì)提示。
這樣就避免了用戶經(jīng)過耐心的等待后才被告訴不合標(biāo)準(zhǔn)的煩惱。
=================================================
處理頁(yè)代碼:
<%@ CODEPAGE="936"%>
<%
Server.ScriptTimeOut=5000 '--腳本超時(shí)設(shè)置為5000
%>
<!--#include file="conn.asp" -->
<%
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") '--建立SA FileUp Object
'oFileUp.Path = Server.MapPath("/upfile/") '--我這里要自己定義文件名,所以沒有使用Path屬性,注意這句被注釋掉了。
strRestrictBy = "" '--文件驗(yàn)證方式,分為extension和ContentType
iCount=0 '--文件上傳數(shù)的計(jì)數(shù)變量
formPath="upfile/" '文件保存位置
'-----------檢查是否有在此位置上傳的權(quán)限-----------這里省略了。
groupID=trim(oFileUp.form("groupID"))
albumID=trim(oFileUp.form("albumID"))
'-----------檢查權(quán)限完成------
if errMsg="" then '----如果到此還沒有錯(cuò)誤
For Each strFormElement In oFileUp.Form
If IsObject(oFileUp.Form(strFormElement)) Then '如果是文件
If Not oFileUp.Form(strFormElement).IsEmpty Then '--文件不為空
flagOK=1
'--不是文件或文件大于限制,設(shè)置錯(cuò)誤信息
If oFileUp.Form(strFormElement).TotalBytes<100 Then
flagOK=0
ElseIf oFileUp.Form(strFormElement).TotalBytes> upFileSize Then
flagOK=0
errMsg=errMsg+"文件:"&oFileUp.Form(strFormElement).UserFileName&" 大于"&upFileSize\1024&"KB!<br>"
Else
strShortFileName = mid(oFileUp.Form(strFormElement).UserFileName,InStrRev(oFileUp.Form(strFormElement).UserFileName, "\")+1) '取得文件名
strExtension = Mid(strShortFileName, InStrRev(strShortFileName, ".")) '取得擴(kuò)展名
If strRestrictBy = "extension" Then '--驗(yàn)證方式為擴(kuò)展名
'strShortFileName = oFileUp.Form(strFormElement).ShortFileName
'======檢查后綴名====
Select Case LCase(strExtension)
Case ".jpg", ".gif", ".bmp",".png"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>錯(cuò)誤:</B> 擴(kuò)展名為 <I>" & strExtension & "</I> 的文件不能被上傳。<BR>")
End Select
Else '--驗(yàn)證方式為MIME類型
strContentType = oFileUp.Form(strFormElement).ContentType
Select Case LCase(strContentType)
Case "image/gif", "image/jpeg", "image/pjpeg"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>錯(cuò)誤:</B> MIME類型為 <I>" & strContentType & "</I> 的文件不能被上傳。<BR>")
End Select
End If '--end if 驗(yàn)證方式
End If 'end if 文件大小判斷
If flagOK=1 Then '如果文件通過檢查,保存文件,并插入數(shù)據(jù)庫(kù)紀(jì)錄
randomize
ranNum=int(900*rnd)+100
filename=year(now())&month(now())&day(now())&hour(now())&minute(now())&second(now())&ranNum&LCase(strExtension)
oFileUp.Form(strFormElement).SaveInVirtual formPath&filename '讓文件名不重復(fù),保存文件,這里用的是SaveInVirtual方法
'--輸出服務(wù)器上的文件路徑
Response.Write oFileUp.Form(strFormElement).ServerName & ":ServerName<BR>"
'--輸出客戶端的文件路徑
Response.Write "<BR><B>文件:</B>"&oFileUp.Form(strFormElement).UserFileName & "<BR>"
'--輸出該文件的大小
Response.Write "<B>大?。?lt;/B>"&oFileUp.Form(strFormElement).TotalBytes & "<BR>"
'===添加文件的信息到數(shù)據(jù)庫(kù)里===
myIndex=right(strFormElement,1) '--取得文件的序號(hào),如file1則取得為1,file2取得為2
temp_photoTitle=oFileUp.form("photoTitle"+myIndex) '--這四行取得對(duì)應(yīng)的標(biāo)題,簡(jiǎn)介,寬度,高度
temp_photoIntro=oFileUp.form("photoIntro"+myIndex)
temp_photoWidth=oFileUp.form("photoWidth"+myIndex)
temp_photoHeight=oFileUp.form("photoHeight"+myIndex)
'====檢查輸入,為空則給初值==
temp_photoTitle=replace(trim(temp_photoTitle),"'","''")
if temp_photoTitle="" then
temp_photoTitle="沒有填寫"
end if
temp_photoIntro=replace(trim(temp_photoIntro),"'","''")
if temp_photoIntro="" then
temp_photoIntro="沒有填寫"
end if
if temp_photoWidth="" or not IsNumeric(temp_photoWidth) then
temp_photoWidth=160
end if
if temp_photoHeight="" or not IsNumeric(temp_photoHeight) then
temp_photoHeight=120
end if
'===插入數(shù)據(jù)庫(kù)===
FileSize=oFileUp.Form(strFormElement).TotalBytes
sql="insert into TBL_PHOTO(albumID,groupID,userName,addTime,photoFilename,photoTitle,photoIntro,photoClick,photoSize,photoWidth,photoHeight,locked,viewPassword) values("&albumID&","&groupID&",'"&session("userName")&"','"&Now()&"','"&filename&"','"&temp_photoTitle&"','"&temp_photoIntro&"',1,"&FileSize&","&temp_photoWidth&","&temp_photoHeight&",'no','')"
conn.execute sql
sql="update TBL_ALBUM set photoCount=photoCount+1 where albumID="&albumID
conn.execute sql
sql="update TBL_GROUP set photoCount=photoCount+1 where groupID="&groupID
conn.execute sql
'===輸出上傳成功信息===
iCount=iCount+1
End If
Else
Response.Write strFormElement & "對(duì)象為空!"
End If '--end if 對(duì)象為空
End If '--end if 是否是文件
Next
Set oFileUp = Nothing '刪除此對(duì)象
end if '--end if 沒有錯(cuò)誤信息
response.write "<br>"&iCount&" 個(gè)文件上傳結(jié)束!"
response.write "<br><a href='photo_listphoto.asp?albumID="&albumID&"'><B>返回相冊(cè)</B></a>"
'=====如果有錯(cuò),輸出錯(cuò)誤信息=====
if errMsg<>"" then
response.write "<br>"&errMsg
response.write "<INPUT type='button' onClick='history.go(-1)' value='返回' class='myInput'>"
end if
conn.close
set conn=nothing
%>
===================================================
看完了實(shí)例,下面對(duì)SA FileUP的屬性和方法進(jìn)行簡(jiǎn)單的介紹,免得大家初次接觸感到發(fā)暈。
這些是我覺得比較常用的,例句和注釋都是按我的理解寫的。
如果大家在應(yīng)用中發(fā)現(xiàn)有什么問題,請(qǐng)指出。謝謝。
建立SA FileUp 對(duì)象的方法:
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
取出表單所有項(xiàng)的方法:
For Each strFormElement In oFileUp.Form
用 oFileUp.Form(strFormElement)就可以引用每個(gè)對(duì)象,文件也是這樣
注意:如果是多選下拉框,則用oFileUp.FormEx(strFormElement)
可以這樣來遍歷它。
For Each strSubItem In oFileUp.FormEx(strFormElement)
Response.Write( strSubItem & "<BR>")
Next
Next
ContentType屬性:
oFileUp.Form(strFormElement).ContentType
可以得到文件的MIME類型
IsEmpty屬性
oFileUp.Form(strFormElement).IsEmpty
可以知道用戶是不是指定了一個(gè)無效的文件
MaxBytes屬性
oFileUp.Form(strFormElement).MaxBytes=30000
指定文件的限制,單位為Byte,如果超過它,那么只存儲(chǔ)MaxBytes指定的大小。其余舍棄。
ServerName屬性
oFileUp.Form(strFormElement).ServerName
可以得到文件保存到服務(wù)器的完整路徑。
ShortFilename屬性
oFileUp.Form(strFormElement).ShortFilename
可以得到客戶端的文件名,注意只是文件名,我這里沒有用,因?yàn)閳?bào)錯(cuò)。呵呵。
UserFilename屬性
oFileUp.Form(strFormElement).UserFileName
可以得到客戶端文件的完整路徑??梢暂敵鲆幌陆o用戶看看。
TotalBytes屬性
oFileUp.Form(strFormElement).TotalBytes
可以得到文件的大小,單位為Byte
SaveInVirtual(路徑)方法
oFileUp.Form(strFormElement).SaveInVirtual "upfile/"
oFileUp.Form(strFormElement).SaveInVirtual "upfile/aa.abc"
如果只指定了路徑,則保留原文件名,否則按指定指定文件名保存
服務(wù)器管理員可以禁止掉其他所有方法,但這個(gè)一定會(huì)留的。
SaveAs (文件名)方法
oFileUp.Form(strFormElement).SaveAs "C:\aa\a.tmp"
如果沒有指定路徑,只是指定了文件名,那么將用Path屬性指定的路徑。
Path屬性一會(huì)介紹。
Save方法
oFileUp.Path="D:\wwwroot\abc\upfile\"
注意必須是真實(shí)路徑,可以用Server.MapPath來轉(zhuǎn)換虛擬路徑。
oFileUp.Form(strFormElement).Save
不能指定文件名嘍。
注意:Path屬性必須在提到任何表單項(xiàng)之前,建議放在
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
的后面。前提是你用的話。
Delete (文件名,可選)
oFileUp.Form(strFormElement).Delete
從服務(wù)器上刪除文件,如果不指定文件名,則刪除當(dāng)前的文件。
如果指定的話,必須是文件的完整路徑。
Flush方法
oFileUp.Flush
當(dāng)你不想保存任何東西的時(shí)候,可以用它來放棄全部的輸入流。
相關(guān)文章
如何遠(yuǎn)程調(diào)用ACCESS數(shù)據(jù)庫(kù)[要求加精!!]
如何遠(yuǎn)程調(diào)用ACCESS數(shù)據(jù)庫(kù)[要求加精?。...2006-06-06javascript asp教程第十一課--Application 對(duì)象
javascript asp教程第十一課--Application 對(duì)象...2007-03-03asp快速開發(fā)方法之?dāng)?shù)據(jù)操作實(shí)例代碼
asp快速開發(fā)方法之?dāng)?shù)據(jù)操作實(shí)例代碼...2007-08-08ASP編程入門進(jìn)階(十八):FSO組件之文件操作(下)
ASP編程入門進(jìn)階(十八):FSO組件之文件操作(下)...2007-01-01