Frog Frog Recommended: Frog Frog ASP Upload Components, (Has Comments)

xiaoxiao2021-03-05  29

Frog Frog Recommended: Frog Frog ASP Upload Components, (Has Comments)

<% 'When there are both text fields and file domains in the form, we must set the encoding type of the form to "Multipart / Form-Data" Type' This time the encoded file uploaded is not directly removed from the value of the text. And the binary data in the file domain, which requires the split sheet single field 'in the uploaded data stream with a random separator between each form field, this separator is constant in the same stream, different The stream separator is unchanged, 'This separator is at the beginning of the stream, and at a ChRB (13) chrb (10), we know this separator to traverse the split sheet.' For the file domain, we have to resolve the field name, file name, file type, and file content. The domain name is the preamble with "name =", and it is included in a pair of dual quotes, the value of the file name is "filename =" as a preamble It is also included in double quotes, which contain the full path and file name of the file, followed by a pair of carriage return, and the string "Content-Type:" And the content between the two pairs of carriage return is the file type string, and the two pairs of carriage return to a pair of carriage return lines are file content 'For text domains, we can analyze his value, The name of the domain is after "Name =", with a double-quoted number package, two pairs of carriage return to the value of the domain separator starting with a pair of carriage return, 'Of course, the stream is uploaded. In binary format, you need to use some operation binary functions when you operate, rather than usual operation string functions, such as Leftb, MIDB, INSTRB, etc., the following is the implementation of the algorithm Class getPost Private BDataStr, SeprationStr, WAWA_STREAM ' information, form field separator characters between the 'class initialization Private Sub Class_Initialize set wawa_stream = CreateObject ( "Adodb.Stream")' Create a global flow wawa_stream.mode = 3 'write mode wawa_stream.type = 1' binary reading mode wawa_stream. Open 'Open BDataStr = Request.binaryRead (Request.Totalbytes)' Get all data of uploaded WAWA_STREAM.WRITE BDATASTR 'Read Data SeprationStr = Leftb (BDataStr, ClNG (INSTRB (BDataStr, Chrb (13) Chrb (10)) ) -1) 'Divide characters String End Sub 'class destructor, unloading global stream object Private Sub Class_Terminate wawa_stream.close set wawa_5xSoft_Stream = nothing End Sub' return file type form field values ​​Dim L1 (binary) Public Function GetFile (FieldName), DataStart, DataLng L1 = INSTRB (BDataStr, GetBinary ("Name =" CHR (34) FieldName CHR (34))) Datastart = INSTRB (L1, BDataStr, Chrb (13) Chrb (10) ChRB (13) ChRB ( 10) 4 Datalng = INSTRB (Datastart, BDataStr, Seprationstr) - DataStart -2 getFile = MIDB (BDataStr, DataStart, Datalng) End Function '

Return to file type PUBLIC FUNCTION GETFILETYPE (FieldName) DIM L1, DATASTART, DATALNG L1 = INSTART, DATALNG L1 = INSTART, DATALNG L1 = INSTRB (BDataStr, GetBinary ("Name =" CHR (34) FieldName CHR (34)) DataStart = INSTRB (L1, BDataStr, GetBinary ("Content-Type:")) 13 Datalng = INSTRB (Datastart, BDataStr, Chrb (13) Chrb (10) ChRB (13) Chrb (10)) - DataStart getFilety = GetText (MIDB (BDataTr, DataStart, Datalng)) End Function 'Return file original path PUBLIC FUNCTION GETFILEPATH (FieldName) DIM L1, DATASTART, DATALNG L1 = INSTRB (BDataStr, GetBinary ("Name =" CHR (34)) FieldName CHR (34)) ) DataStart = INSTRB (L1, BDataStr, GetBinary ("FileName =")) 9 Datalng = INSTRB (Datastart, BDataStr, Chrb (13) ChRB (10)) - DataStart getFilePath = GetText (MIDB (BDatatr, DataStart 1 , Datalng-2)) 'Remove the left and rightmost double quotes, don't know why the double quotation marks on the right should subtract 2 end function' Return the suffix name function getExtendName (FieldName) filename = getFilePath (FieldName) if Isnull (FILENAME) OR FileName = "" Then getExtendName = "" EXIT function end if getExtendName = MID (filename, INSTRRRRRRRRRREV (FileName, ")) End function 'Returns File Type Domain value (binary) Public function getFilesize (FieldName) Dim L1, DataStart, Datalng L1 = INSTART, DATALNG L1 = INSTRB (BDataStr, GetBinary ("Name =" CHR (34) FieldName CHR (34)) DataStart = INSTRB (L1, BDataStr, ChRB (13) CHRB (10) CHRB (13) CHRB (10)) 4 Datalng = INSTRB (DataStart, BDataStr, Seprationstr) - Datastart -2 getFileSize = Datalng End Function 'Remove from binary strings Table single field value (string) Public function retfieldtext (fieldname) DIM L1, DATASTART, DATALNG L1 = INSTRB (BDataStr, GetBinary ("Name =" CHR (34) FieldName

CHR (34))) DataStart = INSTRB (L1, BDataStr, Chrb (13) Chrb (10) CHRB (13) Chrb (10)) 4 DataNG = INSTRB (Datastart, BDataStr, Seprationstr) - DataStart-2 RetfieldText = GetText (MIDB (BDataStr, DataStart, Datalng) end function 'Returns a string after the random number connected, used to build file name Function getrandstr () Dim rannum randomize rannum = int (90000 * rND) 10000 Getrandstr = Year (now) & Month (now) & DAY (NOW) & Hour (NOW) & Minute (NOW) & Second (Now) & Rannum End Function

'Convert binary outer code series into VB string private function getText (STR1R) DIM S, T, T1, I S = ": t =" ": t1 =" "for i = 1 to lenb (str1R) T = ASCB (MIDB (STR1R, I, 1)) 'Removes the outer code IF NOT (T> 127) of the byte to 0, indicating the English character S = S CHR (T) ELSE I = i 1 'When it is Chinese characters, take the second byte t1 = ASCB (MIDB (STR1R, I, 1)) s = s chr (t * 256 t1)' combines Chinese characters two bytes to an ANSI code end If Next getText = s end function 'converts strings to binary series Private function GetBinary (STR1) DIM T2, T1 for i = 1 to Len (str1) T1 = CSTR (HEX (ASC (STR1, I, 1) )))) = T2 = T2 chRB (ClNG ("& H" TRIM (T1))) ELSE T2 = T2 CHRB (ClNG ("& H") MID (TRIM (T1), 1, 2)) T2 = T2 CHRB (CLNG ("& H") MID (Trim (T1), 3, 2)) end if next getbinary = t2 end function 'Save uploaded files on the server's hard drive on the server PUBLIC Function Savetofile (FieldName, FullPath) DR 'Defines Creating a stream Savetofile = "" if trim (fullpath) = "" or filename = "" "" The exit function "detects whether the parameter has real data if Right (FullPath, 1) =" / "THEN EXIT FUNCTION 'Detective Path The correctness of SET DR = CreateObject (" AdoDb.Stream ") Dr.Mode = 3' Read and write mode Dr.Type = 1 'binary mode Dr.Open' Open DIM L1, D Atastart, Datalng L1 = INSTART (BDataStr, GetBinary ("Name =" CHR (34))) 'Gets the location of the File domain Datastart = INSTRB (L1, BDataStr, Chrb (13) CHRB ( 10) CHRB (13) chrb (10)) 4 'entity data start position Datalng = INSTRB (Datast, BDataStr, ChRB (13) chrb (10) chrb (13) chrb (10)) - DataStart 'solid data size WAWA_STREAM.PSITION = DATASTART-1'

Set the global stream, because the global streaming and global data BDataTr corresponds to WAWA_STREAM.COPYTO DR, DATALNG 'Gets Data Dr.Savetofile FullPath, 2' Save in the Specified Location Dr.Close 'Close Flow SET DR = Nothing' Concentrated SaveTofile = MID (filename, INSTRREV (FileName, "/") 1) 'Returns the file name end function end class% of the upload file

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

New Post(0)