<!--#INCLUDE FILE="../../FUNCTIONS/PUBLIC_FUNCTIONS.ASP" -->
<!--#INCLUDE FILE="../../FUNCTIONS/OOCL_FUNCTIONS.ASP"-->
<!--#INCLUDE FILE="../INCLUDES/LOCAL_VARIABLES.ASP"-->
<!--#INCLUDE FILE="../INCLUDES/AUTHENTICATE.ASP"-->
<!--#INCLUDE FILE="../INCLUDES/FILEUPLOAD.ASP"-->
<%
if UCase(Request.ServerVariables("REQUEST_METHOD"))<>"POST" then
Response.Redirect Request.ServerVariables("HTTP_REFERER")
end if
Set UploadRequest=CreateObject("Scripting.Dictionary")
RequestBin=Request.BinaryRead(Request.TotalBytes)
GetUpload RequestBin
If ConnectDB("[LSD DSN Name]",oConn,false) Then
set oRs=CreateObject("ADODB.Recordset")
oRs.Open "Doc_filing_index_attachment",oConn,1,3,2
if Err.number<>0 then
Set oRs=Nothing
bOOCLIsErr=true
strOOCLErrMsg=strOOCLErrMsg & arrUnknowErr(2)
else
for i=0 to UploadRequest("Comment").count-1
if len(UploadRequest("Attachment")(i)("Value"))>0 then
oRs.AddNew
oRs("Doc_index")=Request.QueryString("DocIndex")
oRs("Image_file").AppendChunk UploadRequest("Attachment")(i)("Value")
oRs("Image_type")=UploadRequest("Attachment")(i)("ContentType")
oRs("Comment")=UploadRequest("Comment")(i)("Value")
end if
oRs.Update
next
oRs.Close
end if
else
bOOCLIsErr=true
strOOCLErrMsg=strOOCLErrMsg & arrUnknowErr(0)
end if
FreeDBRes
Response.Redirect Request.ServerVariables("HTTP_REFERER")
%>
<%
sub GetUpload(FormData)
Dim DivStr,DivLen,PosOpenBoundary,PosCloseBoundary
Dim FieldNameStart,FormFieldName,FieldNameSize,FormFieldData,DataStart,DataEnd,DataSize
Dim FieldFileNameStart,FormFileName,FieldFileNameSize
Dim FieldFileCTStart,FormFileCT,FieldFileCTSize
'分隔标志串(+CRLF),
DivStr=LeftB(FormData,InStrB(FormData,str2bin(VbCrLf))-1)
'分隔标志串长度
DivLen=LenB(DivStr)
PosOpenBoundary=InStrB(FormData,DivStr)
PosCloseBoundary=InStrB(PosOpenBoundary+1,FormData,DivStr)
Do until PosCloseBoundary=lenb(FormData) or PosCloseBoundary=0 '(PosOpenBoundary=lenb(FormData))
dim Field,FirstField,bIsFile
bIsFile=false
FormFieldName=""
Set Field=CreateObject("Scripting.Dictionary")
'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 PosCloseBoundary=0 then
PosCloseBoundary=lenb(FormData)
end if
If FieldFileNameStart<PosCloseBoundary And FieldFileNameStart>PosopenBoundary Then
FieldFileNameSize=InStrB(FieldFileNameStart,FormData,ChrB(34))-FieldFileNameStart '(")的ASC值=34
FormFileName=bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))
Field.Add "FilePath",FormFileName
Field.Add "FileName",GetFileName(FormFileName)
bIsFile=true
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))
Field.Add "ContentType",FormFileCT
End If
'数据起始位置:2个CRLF开始
If bIsFile Then
DataStart=InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf))+4
DataEnd=InstrB(DataStart,FormData,DivStr)-2
FormFieldData=MidB(FormData,DataStart,DataEnd-DataStart)
Else
DataStart=InstrB(FieldNameStart,FormData,str2bin(VbCrLf))+4
DataEnd=InstrB(DataStart,RequestBin,DivStr)-2
FormFieldData=bin2str(MidB(FormData,DataStart,DataEnd-DataStart))
End If
Field.Add "Value",FormFieldData
Field.Add "FieldDataBgnPos",DataStart
Field.Add "FieldDataLength",DataEnd-DataStart
if UploadRequest.Exists(FormFieldName) then
iCount=UploadRequest(FormFieldName).Count
UploadRequest(FormFieldName).Add iCount,Field
else
Set FirstField=CreateObject("Scripting.Dictionary")
FirstField.Add 0,Field
UploadRequest.Add FormFieldName,FirstField
end if
PosOpenBoundary=PosCloseBoundary
PosCloseBoundary=InStrB(PosOpenBoundary+1,FormData,DivStr)
loop
End sub
'把二进制字符串转换成普通字符串函数
Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag,i
'中文字符Skip标志
skipflag=0
ccc=""
If Not IsNull(binstr) Then
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 Then
clow=MidB(binstr,i,1)
'判断是否中文的字符
If AscB(clow)>127 Then
'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
ccc=ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc=ccc & Chr(AscB(clow))
End If
Else
skipflag=0
End If
Next
End If
bin2str=ccc
End Function
'把普通字符串转成二进制字符串函数
Function str2bin(varstr)
dim i,varchar,varasc
str2bin=""
For i=1 To Len(varstr)
varchar=mid(varstr,i,1)
varasc=Asc(varchar)
'asc对中文字符求出来的值可能为负数,
'加上65536就可求出它的无符号数值
'-1在机器内是用补码表示的0xffff,
'其无符号值为65535,65535=-1+65536
'其他负数依次类推。
If varasc<0 Then
varasc=varasc+65535
End If
'对中文的处理:把双字节低位和高位分开
If varasc>255 Then
varlow=Left(Hex(Asc(varchar)),2)
varhigh=right(Hex(Asc(varchar)),2)
str2bin=str2bin & chrB("&H" & varlow) & chrB("&H" & varhigh)
Else
str2bin=str2bin & chrB(AscB(varchar))
End If
Next
End Function
'取得文件名(去掉Path)
Function GetFileName(FullPath)
If FullPath<>"" Then
FullPath=StrReverse(FullPath)
if InStr(1,FullPath,"\")>0 then
FullPath=Left(FullPath,InStr(1,FullPath,"\")-1)
GetFileName=StrReverse(FullPath)
else
GetFileName=StrReverse(FullPath)
end if
Else
GetFileName=""
End If
End Function
%>