Multi-table single field without component file upload

zhaozj2021-02-11  207

Recently, some people often ask such questions, reposted here, content:

1. Database Table Structure: UserId: Text (User ID) FileContentType: Text (used to save the type of upload file, EG: "Application / Msword", mainly used to use this file correctly download this file) FileContent : Ole Object (save file data)

2. HTML file MuploadFile.htm

'This is used to indicate start file data upload file to send:


'This is used to indicate the file data end

3. ASP file MUPLOADFILE.ASP

<% Response.expires = 0function bin2str (binstr) DIM VARLEN, CLOW, CCC, Skipflag

Skipflag = 0 ccc = "" "if not isnull (binstr) Then varlen = lenb (binstr) for i = 1 to varlenix 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.TotalBytesbnCRLF = chrB (13) & chrB (10) binHTTPHeader = Request.BinaryRead (varByteCount) Divider = LEFTB (binHTTPHeader, INSTRB (binHTTPHeader, bnCRLF) - 1) 'starts reading data Do while lenB non-file field ( Binhttpheader> 46 binheaderdata = leftb (binhttpheader, instib (binhttpheader, bncrlf & bncrlf) -1) stride = 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) 'judges file data beginning 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)

'Non-File Upload Field Variable Assocute StrfieldName & "=" "" & StrfieldValue & "BINHTTPHEADER = MIDB (BinhttpHeader, INSTRB (Datastart 1, Binhttpheader, Divider) Loop

'Begins processing the file data Do while lenB (binHTTPHeader)> 46 binHeaderData = LeftB (binHTTPHeader, INSTRB (binHTTPHeader, bnCRLF & bnCRLF) -1) strHeaderData = bin2str (binHeaderData)' read file upload Content-Type lngFileContentTypeStart = Instr (strHeaderData , "Content-Type:") Len ( "Content-Type:") strFileContentType = Trim (Mid (strHeaderData, lngFileContentTypeStart) file name lngFileNameStart) strFileContentType = Replace (strFileContentType, vbCRLF, vbNullString) 'read uploaded = 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) 'read the data uploaded DataStart = INSTRB (binHTTPHeader, bnCRLF & bnCRLF) 4 DataEnd = INSTRB (DataStart 1, binHTTPHeader, divider) - DataStart If strFileName <> "" THEN BINFIELDVALUE = MIDB (B Inhttpheader, DataStart, DataEND 'Write uploaded files to database set conn = server.createObject ("adoDb.connection") Conn.open "DSN = ABC" SQL = "SELECT * from user_file" set = 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 end if binhttpheader = midb (binhttpheader, instib (Datastart 1, BinhttpHeader, Divider) loop%> 4. Download the user uploaded file <% response.buffer = trueresponse.clear

Userid = Request ("UserID")

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, 3RESPONSE.CONTENTTYPE = RS (" FileContentType ")

lngOffset = 0conChunkSize = 1024lngPictSize = rs ( "FileContent"). ActualSizeDo While lngOffset lngPictSize Then Exit DoLoop

rs.closset = Nothingconn.closset conn = nothing%>

These, I hope this method can help everyone. :)

转载请注明原文地址:https://www.9cbs.com/read-5005.html

New Post(0)