日期:2013-07-25  浏览次数:21277 次

化境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
%&g