在WEBCLASS中使用文件上传功能
类别: ASP教程
在webclass中使用文件上传功能
Public Sub OnStartPage(PassedRequest As Request)
\'------------------定义局部变量----------------------
Dim varByteCount
Dim i
\'---------------------------------------------------
\'------------------建立ASP对象-----------------------
Set MyRequest = PassedRequest
\'---------------------------------------------------
\'------------------读取客户端传来的全部数据-----------
varByteCount = MyRequest.TotalBytes
lngArrayLen = varByteCount - 1
ReDim binArray(varByteCount - 1)
binArray = MyRequest.BinaryRead(varByteCount)
\'---------------------------------------------------
\'--------------------获取定界符---------------------
intDjfLen = 0
Do Until binArray(intDjfLen + 1) = 13
intDjfLen = intDjfLen + 1
Loop
ReDim binDjf(intDjfLen)
For i = 0 To intDjfLen
binDjf(i) = binArray(i)
Next
\'---------------------------------------------------
End Sub
在webclass中使用
dim upload as new uploadfile
upload.onstartpage(request)
然后就可以用该类提供的方法了进行操作了,这个组件的功能比chinaasp upload要差些。但已经足够使用了
其他改动
1、为了能用getthevalue方法正确取得input type 为checkbox,radio等的值,在
FindtheName中加入错误处理
Private Function FindTheName(nm As String) As Long
On Error GoTo FindTheNameError
\'******************************参数说明*****************************
\'* *
\'* nm: 要寻找的 Form 元素名 *
\'* 返回值: 成功―― 找到时的地址,失败―― -1 *
\'* *
\'*******************************************************************
\'------------------定义局部变量----------------------
Dim s As Long
Dim e As Long
Dim i As Long
Dim binTmp() As Byte
Dim strName As String
\'---------------------------------------------------
\'------------------寻找要取得值的Form 元素名------------------------
s = 0
Do While 1
s = FindTheDjf(s)
If s <> -1 Then
s = s + intDjfLen + 41
e = s
Do While binArray(e + 1) <> 34
e = e + 1
Loop
ReDim binTmp(e - s)
For i = s To e
binTmp(i - s) = binArray(i)
Next
strName = StrConv(binTmp, 64)
If StrComp(nm, strName) = 0 Then
FindTheName = e + 1
Exit Do
End If
Else
FindTheName = -1
Exit Do
End If
Loop
\'--------------------------------------------------------------
Exit Function
FindTheNameError:
FindTheName = -1
End Function
2、删除类声明中的
Private MyScriptingContext As ScriptingContext定义
Public Sub OnStartPage(PassedRequest As Request)
\'------------------定义局部变量----------------------
Dim varByteCount
Dim i
\'---------------------------------------------------
\'------------------建立ASP对象-----------------------
Set MyRequest = PassedRequest
\'---------------------------------------------------
\'------------------读取客户端传来的全部数据-----------
varByteCount = MyRequest.TotalBytes
lngArrayLen = varByteCount - 1
ReDim binArray(varByteCount - 1)
binArray = MyRequest.BinaryRead(varByteCount)
\'---------------------------------------------------
\'--------------------获取定界符---------------------
intDjfLen = 0
Do Until binArray(intDjfLen + 1) = 13
intDjfLen = intDjfLen + 1
Loop
ReDim binDjf(intDjfLen)
For i = 0 To intDjfLen
binDjf(i) = binArray(i)
Next
\'---------------------------------------------------
End Sub
在webclass中使用
dim upload as new uploadfile
upload.onstartpage(request)
然后就可以用该类提供的方法了进行操作了,这个组件的功能比chinaasp upload要差些。但已经足够使用了
其他改动
1、为了能用getthevalue方法正确取得input type 为checkbox,radio等的值,在
FindtheName中加入错误处理
Private Function FindTheName(nm As String) As Long
On Error GoTo FindTheNameError
\'******************************参数说明*****************************
\'* *
\'* nm: 要寻找的 Form 元素名 *
\'* 返回值: 成功―― 找到时的地址,失败―― -1 *
\'* *
\'*******************************************************************
\'------------------定义局部变量----------------------
Dim s As Long
Dim e As Long
Dim i As Long
Dim binTmp() As Byte
Dim strName As String
\'---------------------------------------------------
\'------------------寻找要取得值的Form 元素名------------------------
s = 0
Do While 1
s = FindTheDjf(s)
If s <> -1 Then
s = s + intDjfLen + 41
e = s
Do While binArray(e + 1) <> 34
e = e + 1
Loop
ReDim binTmp(e - s)
For i = s To e
binTmp(i - s) = binArray(i)
Next
strName = StrConv(binTmp, 64)
If StrComp(nm, strName) = 0 Then
FindTheName = e + 1
Exit Do
End If
Else
FindTheName = -1
Exit Do
End If
Loop
\'--------------------------------------------------------------
Exit Function
FindTheNameError:
FindTheName = -1
End Function
2、删除类声明中的
Private MyScriptingContext As ScriptingContext定义
-= 资 源 教 程 =-
文 章 搜 索