#12001/11/21 16:11:08
<%
Response.Expires=0
Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
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
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
varByteCount = Request.TotalBytes
bnCRLF = chrB( 13 ) & chrB( 10 )
binHTTPHeader=Request.BinaryRead(varByteCount)
Divider = LEFTB( binHTTPHeader, INSTRB( binHTTPHeader, bnCRLF ) - 1 )
'¿ªÊ¼¶Á·ÇÎļþÓòµÄÊý¾Ý
Do while lenB(binHTTPHeader)>46
binHeaderData = LeftB(binHTTPHeader, INSTRB( binHTTPHeader, bnCRLF & bnCRLF )-1)
strHeaderData=bin2str(binHeaderData)
lngFieldNameStart=Instr(strHeaderData,"name="&chr(34))+Len("name="&chr(34))
lngFieldNameEnd=Instr(lngFieldNameStart,strHeaderData,chr(34))
strFieldName=Mid(strHeaderData,lngFieldNameStart,lngFieldNameEnd-lngFieldNameStart)
strFieldName=Trim(strFieldName)
strFieldName=Replace(strFieldName,vbcrlf,vbnullstring)
'ÅжÏÎļþÊý¾Ýʱºò¿ªÊ¼
If strComp(strFieldName,"FileUploadStart",1)=0 Then
binHTTPHeader=MIDB(binHTTPHeader,INSTRB( DataStart + 1, binHTTPHeader, divider ))
exit do
End if
DataStart = INSTRB( binHTTPHeader, bnCRLF & bnCRLF ) + 4
DataEnd = INSTRB( DataStart + 1, binHTTPHeader, divider ) - DataStart
binFieldvalue=MIDB( binHTTPHeader, DataStart, DataEnd )
strFieldvalue=bin2str(binFieldvalue)
strFieldvalue=Trim(strFieldvalue)
strFieldvalue=Replace(strFieldvalue,vbcrlf,vbnullstring)
'·ÇÎļþÉÏ´«Óò±äÁ¿¸³Öµ
execute strFieldName&"="""&strFieldvalue&""""
binHTTPHeader=MIDB(binHTTPHeader,INSTRB( DataStart + 1, binHTTPHeader, divider ))
loop
'¿ªÊ¼´¦ÀíÎļþÊý¾Ý
Do while lenB(binHTTPHeader)>46
binHeaderData = LeftB(binHTTPHeader, INSTRB( binHTTPHeader, bnCRLF & bnCRLF )-1)
strHeaderData=bin2str(binHeaderData)
'¶ÁÈ¡ÉÏ´«ÎļþµÄContent-Type
lngFileContentTypeStart=Instr(strHeaderData,"Content-Type:")+Len("Content-Type:")
strFileContentType=Trim(Mid(strHeaderData,lngFileContentTypeStart))
strFileContentType=Replace(strFileContentType,vbCRLF,vbNullString)
'¶ÁÈ¡ÉÏ´«µÄÎļþÃû
lngFileNameStart=Instr(strHeaderData,"filename="&chr(34))+Len("filename="&chr(34))
lngFileNameEnd=Instr(lngFileNameStart,strHeaderData,chr(34))
strFileName=Mid(strHeaderData,lngFileNameStart,lngFileNameEnd-lngFileNameStart)
strFileName=Trim(strFileName)
strFileName=Replace(strFileName,vbCRLF,vbNullString)
'¶ÁÈ¡ÉÏ´«ÎļþÊý¾Ý
DataStart = INSTRB( binHTTPHeader, bnCRLF & bnCRLF ) + 4
DataEnd = INSTRB( DataStart + 1, binHTTPHeader, divider ) - DataStart
If strFileName<>"" Then
binFieldvalue=MIDB( binHTTPHeader, DataStart, DataEnd )
'½«ÉÏ´«µÄÎļþдÈëÊý¾Ý¿â
set rs= Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_connNews_STRING
rs.Source = "SELECT * FROM User_File"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
rs.addnew
rs("UserID")=UserID
rs("FileContentType")=strFileContentType
rs("FileContent").AppendChunk binFieldvalue
rs.update
rs.close
set rs=Nothing
End if
binHTTPHeader=MIDB(binHTTPHeader,INSTRB( DataStart + 1, binHTTPHeader, divider ))
loop
%>
以上代码在上传图片时不成功,原始代码是借用他人的代码,进行修改。