<% server.scripttimeout = 5400 const ForWriting = 2 const TristateTrue = -1 crlf = chr(13) & chr(10) Dim DocumentPath,MaxDocumentSize DocumentPath = Request.QueryString("DP") MaxDocumentSize = Request.QueryString("MaxDocumentSize") function getFieldName( infoStr) sPos = inStr( infoStr, "name=") endPos = inStr( sPos + 6, infoStr, chr(34) & ";") if endPos = 0 then endPos = inStr( sPos + 6, infoStr, chr(34)) end if getFieldName = mid( infoStr, sPos + 6, endPos - (sPos + 6)) end function ' This function retreives a file field's filename function getFileName( infoStr) sPos = inStr( infoStr, "filename=") endPos = inStr( infoStr, chr(34) & crlf) getFileName = mid( infoStr, sPos + 10, endPos - (sPos + 10)) end function ' This function retreives a file field's mime type function getFileType( infoStr) sPos = inStr( infoStr, "Content-Type: ") getFileType = mid( infoStr, sPos + 14) end function postData = "" Dim biData biData = Request.BinaryRead(Request.TotalBytes) for nIndex = 1 to LenB( biData) postData = postData & Chr(AscB(MidB( biData, nIndex, 1))) next contentType = Request.ServerVariables( "HTTP_CONTENT_TYPE") ctArray = split( contentType, ";") if trim(ctArray(0)) = "multipart/form-data" then errMsg = "" ' grab the form boundry... bArray = split( trim( ctArray(1)), "=") boundry = trim( bArray(1)) ' now use that to split up all the variables! formData = split( postData, boundry) ' now, we need to extract the information for each variable and it's data dim myRequest, myRequestFiles(9, 3) Set myRequest = CreateObject("Scripting.Dictionary") 'Set myRequestFiles = CreateObject("Scripting.Dictionary") fileCount = 0 for x = 0 to ubound( formData) ' two sets of crlf mark the end of the information about this field ' everything after that is the value infoEnd = instr( formData(x), crlf & crlf) if infoEnd > 0 then ' pull the info for this field, minus the stuff at the ends... varInfo = mid( formData(x), 3, infoEnd - 3) ' pull the value for this field, being sure to ' skip the crlf pairs at the start and the crlf-- at the end varValue = mid( formData(x), infoEnd + 4, len(formData(x)) - infoEnd - 7) ' now, is this a file? if (instr( varInfo, "filename=") > 0) then ' place it into our files array ' While this supports more than one file uploaded at a time ' we only consider the single file case in this example myRequestFiles( fileCount, 0) = Len(varValue) myRequestFiles( fileCount, 1) = varValue myRequestFiles( fileCount, 2) = getFileName( varInfo) myRequestFiles( fileCount, 3) = getFileType( varInfo) Dim PicType PicType = myRequestFiles( fileCount, 3) If myRequestFiles( 0, 0) > MaxDocumentSize * 1024 Then errMsg = "Document size exceeds "& MaxDocumentSize &" KB limit: "& Formatnumber(myRequestFiles( 0, 0)/1024,2) &" KB" End If fileCount = fileCount + 1 else ' it's a regular field myRequest.add getFieldName( varInfo), varValue end if end if next else errMsg = "Wrong encoding type!" end if if errMsg = "" then set lf = server.createObject( "Scripting.FileSystemObject") browserType = UCase( Request.ServerVariables( "HTTP_USER_AGENT")) if (inStr(browserType, "WIN") > 0) then sPos = inStrRev( myRequestFiles( 0, 2), "\") fName = mid( myRequestFiles( 0, 2), sPos + 1) end if if (inStr(browserType, "MAC") > 0) then fName = myRequestFiles(0, 2) end if ' If your upload path is different, set that here filePath = DocumentPath &"/"& fName savePath = server.mapPath( filePath) set saveFile = lf.createtextfile(savePath, true) saveFile.write( myRequestFiles(0, 1)) saveFile.close End If %> <% if errMsg = "" then Response.Write fName&" uploaded successfully!" Response.Write "" else Response.Write errMsg end if %>

Upload again