\' \'~~~~~ PARSE HEADER DATA OF FIRST ELEMENT FROM BYTE ARRAY ~~~~~~~~~~~~~~~~~~~~~~ intCount = 1 \'binArray is base zero while Right(strHeadData, 4) <> chr(13) & chr(10) & chr(13) & chr(10) strHeadData = strHeadData & Chr(ascb(midB(binArray,intCount,1))) intCount = intCount + 1 wend \'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\'~~~~~ PARSE FILE NAME ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \'#1 Find the beginning of the file tag name (UploadFormName) intFileTagStart = InStr(strHeadData, \"UploadFormName\") \'#2 Find the beginning of the FilePath (\'filename=\' plus 10 chars) intPathNameStart = InStr(intFileTagStart, strHeadData, \"filename=\") + 10 intContentTypeStart=InStr(intFileTagStart,strHeadData,\"Content-Type:\")+13 intContentTypeEnd = InStr(intContentTypeStart, strHeadData, vbCrLf) \'#3 Find the quote at the end of the file name sent by the user intFileNameEnd = InStr(intFileTagStart, strHeadData, vbCrLf) - 1 \' Check if no file name was sent (exit sub for this example) \'#4 Parse the path name strPathName = Mid(strHeadData, intPathNameStart, intFileNameEnd - intPathNameStart) strContentType=Mid(strHeadData, intContentTypeStart, intContentTypeEnd - intContentTypeStart) \'#5 Find the starting position the file name For intCount = intFileNameEnd To intPathNameStart Step -1 If Mid(strHeadData, intCount, 1) = \"\\\" Then intFileNameStart = intCount + 1 Exit For End If Next \'#6 Now parse the file name strFileName = Mid(strHeadData, intFileNameStart, intFileNameEnd - intFileNameStart) \'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\'~~~~~ START AND END OF THE UPLOAD FILE DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lngFileDataStart = InStr(intFileTagStart, strHeadData, vbCrLf & vbCrLf) + 4 lngFileDataEnd = CLng(varByteCount) - (Len(strDelimeter) + 6) \'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\'~~~~~ SAVE THE DATA TO DB~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rst.Open \"images\",conn,1,3,2
rst.AddNew
rst.Fields(\"ContentType\")=strContentType rst.Fields(\"Size\")=lngFileDataEnd-lngFileDataStart rst.Fields(\"Filename\")=strFilename For lngCount = lngFileDataStart To lngFileDataEnd step BLOCKSIZE rst.Fields(\"ImageData\").AppendChunk midb(binArray,lngCount,BLOCKSIZE) Next rst.Update
rst.close rst.open \"Select max(ImageID) as ImageID from images\",conn,1,3 lngID=rst.Fields(\"ImageID\") Response.Write \"ID=\" & lngID & \"<br>\"
rst.Close conn.Close set rst=nothing set conn=nothing
_______ViewImage.asp____ (viser billede fra db\'en) <%@ Language=VBScript %> <%option explicit Response.Expires=-1 dim ImageID dim Image dim Connection dim Result dim sql ImageID = request.querystring(\"ID\") if ImageID <> \"\" then set Connection = server.createobject(\"ADODB.Connection\") Connection.Open \"ImgDB\" set Result = server.createobject(\"ADODB.Recordset\") sql = \"SELECT * FROM Images WHERE ImageID=\" & ImageID Result.Open sql, Connection, 0 if not (Result.eof and Result.bof) then Image = Result.Fields(\"ImageData\").GetChunk(10240000) Response.ContentType = Result.Fields(\"ContentType\") Response.BinaryWrite Image else Response.Write \"ID \'\" & ImageID & \"\' not found in DB.\" end if Result.Close Connection.Close Set Result=nothing Set Connection=nothing else Response.Write \"ID is blank \" end if Response.End %>
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.