2011年6月20日 星期一

[Asp].無組件上傳 (hyUpload)

先透過 .isFile 屬性來判斷要處理的欄位是檔案, 還是一般的字串.

由於是使用 iis 內建的元件, 因此在 x64 (64bit) 和 x86 (32bit) 都可以work.



● 畫面1: 選取檔案 (form.asp).
================================



● 畫面2: 上傳成功 (upload.asp).
================================
(用藍字來顯示 File 的部份, 綠色用來顯示一般的 string 資料.



● 檔案清單:
================================
\form.asp
\upload.asp
\inc\hyFileUpload.inc


● form.asp (source code):
================================
<form method="post" ENCTYPE="multipart/form-data" action="upload.asp">
<br/>userName:<input type="text" name="userName">
<br/>file:<input type="file" name="uploadFile">
<br/><input type="submit" name="submit" value="Upload">
</form>


● upload.asp (source code):
================================
dim apath
apath = server.mapPath(".") & "\"

dim xup
set xup=New HyFileUpload

'// 定義最大值, 單位Byte, 0: 不設限
xup.MaxBytesToAbort = 0
'// 定義預設上傳路徑
xup.Start apath

for each x in xup.Form
response.write "<br/> filed(" & x & ") ==>" & xup.Form(x).IsFile & vbcrlf
if xup.Form(x).IsFile then
response.write "<font color='blue'>"
response.write "<br/>+------Name:" & xup.Form(x).Name & vbcrlf
response.write "<br/>+------FileSize:" & xup.Form(x).FileSize & vbcrlf
response.write "<br/>+------FileName:" & xup.Form(x).FileName & vbcrlf
response.write "<br/>+------FileType:" & xup.Form(x).FileType & vbcrlf
response.write "<br/>+------sDefaultPath:" & xup.Form(x).sDefaultPath & vbcrlf
response.write "</font>"
else
response.write "<font color='green'>"
response.write "<br/>+------Name:" & xup.Form(x).Name & vbcrlf
response.write "<br/>+------Value:" & xup.Form(x).value & vbcrlf
response.write "</font>"
end if
next

set xup=nothing




================================
附註1: 更多相關文章 google 關鍵字下: ASP 無組件上傳
附註2: 特別感謝 e部門, 還有ken, 還有提供我這個 source code 的人.

沒有留言:

張貼留言

Facebook 留言板