[摘要]分隔 Public Property Let DeniedFilesList(dfl) m_strDeniedFilesList = dfl End Property '只写的MaxFile...
分隔
Public Property Let DeniedFilesList(dfl)
m_strDeniedFilesList = dfl
End Property
'只写的MaxFileSize属性,填入各个允许上传文件的大小
Public Property Let MaxFileSize(mfs)
m_lMaxFileSize = mfs
End Property
'只写的TotalMaxFileSize属性,填入允许上传文件的总大小
Public Property Let TotalMaxFileSize(tmfs)
m_lTotalMaxFileSize = tmfs
End Property
Public Property Get Form(index)
Dim Items
If isNumeric(index) Then '是数字?用数字来检索
If index > m_dicForms.Count-1 Then
err.raise 21,"IndexOutOfBound", "文本元素索引越界"
End If
Items = m_dicForms.Items
Set Form = Items(index)
ElseIf VarType(index) = 8 Then '字符串?也行!
If m_dicForms.Exists(index) Then '存在,就返回值
Set Form = m_dicForms.Item(index)
Else '不存在,就给个空值——request对象就是这么做的。
Exit Property
End If
Else '给了一个不是数字也不是字符串的东东?出错!
err.raise 22,"IllegalArgument", "非法的文本元素索引"
End If
End Property
Public Property Get File(index)
Dim Items
If isNumeric(index) Then '是数字?用数字来检索
If index > m_dicFiles.Count-1 Then
err.raise 23,"IndexOutOfBound", "文件元素索引越界"
End If
Items = m_dicFiles.Items
Set File = Items(index)
ElseIf VarType(index) = 8 Then '字符串?也行!
If m_dicFiles.Exists(index) Then '存在,就返回值
Set File = m_dicFiles.Item(index)
Else '不存在,出错!
err.raise 24,"NullRef", "文件元素索引不存在"
End If
Else '给了一个不是数字也不是字符串的东东?出错!
err.raise 25,"IllegalArgument", "非法的表单元素索引"
End If
End Property
Private Sub fill
' 得到数据
m_bRawData=request.binaryread(request.totalbytes)
' 调用这个函数实现递归循环,读取文本/文件单元
Call fillEveryFirstPart(m_bRawData)
End Sub
Private Sub fillEveryFirstPart(data)
Dim const_nameis, const_filenameis, bncrlf, divider, startpos, endpos
Dim part1, firstline
Dim fldname, fldvalue, fElement, filepath, contenttype, ext, afl, dfl
Dim isTypeError, i
' 这就是name="
const_nameis=chrb(110)&chrb(97)&chrb(109)&chrb(101)&chrb(61)&chrb(34)
' 这就是filename="
const_filenameis=chrb(102)&chrb(105)&chrb(108)&chrb(101)&_
chrb(110)&chrb(97)&chrb(109)&chrb(101)&chrb(61)&chrb(34)
' 这是回车<return>
bncrlf=chrb(13) & chrb(10)
' 得到divider,分隔符
divider=leftb(data,instrb(data,bncrlf)-1)
' 起始位置
startpos = instrb(data,divider)+lenb(divider)+lenb(bncrlf)
' 终止位置,从起始位置开始到下一个divider
endpos = instrb(startpos, data, divider)-lenb(bncrlf)
If endpos < 1 Then '没有下一个了!结束!
Exit Sub
End If
part1 = midb(data, startpos, endpos-startpos)
' 得到part1的第一行
firstline = midb(part1, 1, instrb(part1, bncrlf)-1)
'没有filename=",有name=",说明是一个文本单元
'(这里有一个BUG,自己研究一下?当作业吧)
If Not instrb(firstline, const_filenameis) > 0_
And instrb(firstline, const_nameis) > 0 Then
' 得到表单域名称,就是<input type=sometype name=somename>里的somename。
fldname = B2S(midb(part1,_
instrb(part1, const_nameis)+lenb(const_nameis),_
instrb(part1, bncrlf)_
-instrb(part1, const_nameis)-lenb(const_nameis)-1))
' 得到表单域的值
fldvalue = B2S(midb(part1,_
instrb(part1, bncrlf&bncrlf)+lenb(bncrlf&bncrlf),_
lenb(part1)-instrb(part1, bncrlf&bncrlf)+_
lenb(bncrlf&bncrlf)))
If m_dicForms.Exists(fldname) Then
Set fElement = m_dicForms.Item(fldname)
m_dicForms.Remove fldname
Else
Set fElement = new FormElement
End If
fElement.Add fldname&"_"&fElement.Count, fldvalue
m_dicForms.Add fldname, fElement
'有filename=",有name=",说明是一个文件单元
'(这里还是有一个BUG,研究出来没?)
ElseIf instrb(firstline, const_filenameis) > 0_
And instrb(firstline, const_nameis) > 0 Then
' 得到表单域名称,就是<input type=file name=somename>里的somename。
fldname = B2S(midb(part1,_
instrb(part1, const_nameis)+lenb(const_nameis),_
instrb(part1, const_filenameis)_
-instrb(part1, const_nameis)-lenb(const_nameis)-3))
' 得到表单域的值
fldvalue = midb(part1,_
instrb(part1, bncrlf&bncrlf)+lenb(bncrlf&bncrlf),_
lenb(part1)-instrb(part1, bncrlf&bncrlf)+lenb(bncrlf&bncrlf))
' 得到路径
filepath = B2S(midb(part1,_
instrb(part1, const_filenameis)+lenb(const_filenameis),_
instrb(part1, bncrlf)_
-instrb(part1, const_filenameis)-lenb(const_filenameis)-1))
' 得到contenttype
contenttype = B2S(midb(part1,_
instrb(part1, bncrlf)+lenb(bncrlf)+14,_
instrb(part1,_
bncrlf&bncrlf)-instrb(part1, bncrlf)-_
lenb(bncrlf)-14))
If lenb(fldvalue) > 0 Then 'size>0说明有文件传来了。
If m_dicFiles.Exists(fldname) Then
Set fElement = m_dicFiles.Item(fldname)
m_dicFiles.Remove fldname
Else
Set fElement = new FileElement
fElement.Rawdata = m_bRawData
End If
'检查单个文件尺寸
If m_lMaxFileSize > 0 And m_lMaxFileSize < lenb(fldvalue) Then _
err.raise 26,"TooLargeFile", "文件"&fldname&"尺寸过大"
m_lTotalBytes = m_lTotalBytes + lenb(fldvalue)
'检查文件总尺寸
If m_lTotalMaxFileSize > 0 And m_lTotalMaxFileSize < m_lTotalBytes Then
err.raise 27,"TooLargeFiles", "文件总尺寸过大"
End If
'检查文件类型
ext = right(filepath, len(filepath)-instrrev(filepath, "."))
If m_strAllowedFilesList <> "" Then
afl = Split(m_strAllowedFilesList,"
关键词:ASP无组件上传·从原理剖析到实战(下)