日期:2013-01-16  浏览次数:20975 次

'filename: upload.inc
'---------------------------------------------------------------------------
------------------------------------------
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
Function GetUpload(FormData)
    Dim DataStart,DivStr,DivLen,DataSize,FormFieldData
    '分隔标志串(+CRLF)
    DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)
    '分隔标志串长度
    DivLen = LenB(DivStr)
    PosOpenBoundary = InStrB(FormData,DivStr)
    PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
    Set Fields = CreateObject("Scripting.Dictionary")

    While PosOpenBoundary > 0 And PosCloseBoundary > 0
       'name起始位置(name="xxxxx"),加6是因为[name="]长度为6
       FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) +
6
       FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) -
FieldNameStart '(")的ASC值=34
       FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))

       'filename起始位置(filename="xxxxx")
       FieldFileNameStart =
InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10
       If FieldFileNameStart < PosCloseBoundary And FieldFileNameStart >
PosopenBoundary Then
          FieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) -
FieldFileNameStart '(")的ASC值=34
          FormFileName =
bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))
       Else
          FormFileName = ""
       End If

       'Content-Type起始位置(Content-Type: xxxxx)
       FieldFileCTStart =
InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14
       If FieldFileCTStart < PosCloseBoundary  And FieldFileCTStart >
PosOpenBoundary Then
          FieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf
& VbCrLf)) - FieldFileCTStart
          FormFileCT =
bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))
       Else
          FormFileCT = ""
       End If

       '数据起始位置:2个CRLF开始
       DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf & VbCrLf))
+ 4
       If FormFileName <> "" Then
          '数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法
的问题):
          '由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能
正确显示,
          '字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶
数。
          DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1
          FormFieldData = MidB(FormData,DataStart,DataSize)