化境ASP無組件上傳類 - upload_5xsoft 使用手冊 1.0
稻香老農 http://www.5xsoft.com/ [ 下載 ]
目 錄
1.關于 upload_5xsoft
2.運行平臺與注意事項
2.類的成員與對象
3.使用示例
關于 upload_5xsoft
一直以來,由于FileSystemObject的局限,所以ASP最大的難題就是文件上傳,大多解決法就是安裝
第三方上傳組件。可第三方組件有很多問題,有的組件要注冊,有的組件要在表單中加上他的版權信息。
還有的就是組件的兼容問題。
在網上也流傳了很多無組件上傳的代碼,但都是只能上傳文本文件,或是只能將文件上傳到數據庫中。
我這段時間在研究ASP,發現可以不用第三方組件上傳任意類型的文件。就寫了這個類,給大家一
個方便,整個類放在一個文件中: upload_5xsoft.inc 在 Example 目錄下還有一個完整的多文件上傳示
例程序,可以直接使用。
申明:源代碼是完全開放的,可能隨意傳播,但請保留其完整性,未經作者同意,不得用于商業。
運行平臺與注意事項
a)只能運行于 Windows2000+IIS 5,不支持 NT4+IIS4 或是 Win98+PWS, 只要在ASP中加上: <!--#include FILE="upload_5xsoft.inc"--> 就行了
b) 在使用文件上傳時, 表單 form 要加上 enctype="multipart/form-data" 即:
<form name="form1" method="post" action="" enctype="multipart/form-data"> <input type="text" value="abc" name="text1"> <input type=file name="file"> <input type=submit name="submit" value="提交"> </form>
upload_5xsoft的對象
如定義一個上傳對象 <!--#include FILE="upload_5xsoft.inc"--> <% set upload=new upload_5xsoft 'upload就是一個對象 %>
upload_5xsoft 對象成員 file 文件對象集,(是個dictionary對象)
文件對象成員: Count 屬性,文件表單的個數 FileName 屬性,上傳文件的名字 FileSize 屬性,上傳文件的大小(為0是表示沒有文件) FilePath 屬性,上傳前文件所在的路徑 FormName 屬性,文件表單的名字 SaveAs 方法,儲存上傳后文件,有一個參數,路徑要為真實路徑如: 例子: set file=upload.file("file1") 'file1為表單名
response.write "<br>文件名:"&file.FileName
response.write "<br>文件大小:"&file.FileSize
response.write "<br>文件路徑:"&file.FilePath
file.saveAs Server.mappath("/1.jpg")
set file=nothing form 表單數據集,(是個dictionary對象)用來代替 Request.Form count 屬性,表單數 exists 方法,檢查是否有指定的表單名 更多的用法可看 vbscript 的dictionary對象幫助 例子: '得到text1表單的數據,uplaod就是一開始創建的對象
sText=upload.form("text1") Version 屬性,upload_5xsoft類的版本號,如:
response.write upload.Version
使用示例
1.上傳一個jpg文件的示例:
文件1: upload.htm
<html><title>example</title> <body> <form name="form1" method="post" action="upload.asp" enctype="multipart/form-data"> <input type=file name="file1"> <input type=submit name="submit" value="提交"> </form> </body> </html>
文件2: upload.asp
<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 %>
你還可能直接使用作者寫好了的上傳程序在example目錄中
立即下載
若程序有問題,請寫作者聯系 getc@163.com
稻香老農 2001年 4月19日
|