2。HTML文件 muploadfile.htm Form name="upload_file" enctype="multipart/form-data" action="muploadfile.asp" method=post> input type=hidden name="UserID" value="abc"> input type=hidden name="FileUploadStart"> '这里用来表示开始文件数据上传 File to send:
INPUT TYPE="file" name="file_up" size="30">br> INPUT TYPE="file" name="file_up" size="30">br> input type=hidden name="FileUploadEnd"> '这里用来表示文件数据结束 input type=submit value=Submit> /Form>/P>P> 3。ASP文件 muploadfile.asp/P>P>% Response.Expires=0 Function bin2str(binstr) Dim varlen,clow,ccc,skipflag /P>P> 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 /P>P> varByteCount = Request.TotalBytes bnCRLF = chrB( 13 ) chrB( 10 ) binHTTPHeader=Request.BinaryRead(varByteCount) Divider = LEFTB( binHTTPHeader, INSTRB( binHTTPHeader, bnCRLF ) - 1 )/P>P>'开始读非文件域的数据 Do while lenB(binHTTPHeader)>46
'判断文件数据时候开始 If strComp(strFieldName,"FileUploadStart",1)=0 Then binHTTPHeader=MIDB(binHTTPHeader,INSTRB( DataStart + 1, binHTTPHeader, divider )) exit do End if
'将上传的文件写入数据库 set conn = Server.CreateObject("ADODB.Connection") conn.Open "DSN=abc"
SQL="select * from User_File" set rs=server.CreateObject("ADODB.Recordset") rs.Open sql,conn,3,3 rs.addnew rs("UserID")=UserID rs("FileContentType")=strFileContentType rs("FileContent").AppendChunk binFieldValue rs.update rs.close set rs=Nothing conn.Close set conn=Nothing
UserID=request("UserID")/P>P>Set conn=server.createobject("adodb.connection") set rs=server.createobject("adodb.recordset") conn.open "DSN=UploadFile" rs.open "select * from User_File where UserID='"UserID"'",conn,3,3 Response.ContentType = rs("FileContentType")/P>P>lngOffset=0 conChunkSize=1024 lngPictSize=rs("FileContent").ActualSize Do While lngOffset lngPictSize varChunk = rs("FileContent").GetChunk(conChunkSize) Response.BinaryWrite varChunk lngOffset = lngOffset + conChunkSize If lngOffset > lngPictSize Then Exit Do Loop
rs.close set rs=Nothing conn.close set conn=nothing %>/P>P>就是这些了,希望此方法对大家能有所帮助。:)