<% 'This function checks all file attachments. 'Returns: Array of error codes 'Error codes: '0: no error '-1: Filename to short(no selected file) '-2: File to large '-3: zero length file '-4: file extension not allowed function CheckAttachments(ByRef pobjRequest, ByVal pstrAttachmentMethod, ByVal pintMaxSize, _ ByVal pstrExtensionsAllowed) dim objItemKey, objItem, strFilename, strExtension, strContentType, bsValue, intAttachmentSize, objSAFile, blnFile, _ intAttachmentID, intError, aError(), blnAllowedExt redim aError(-1) for each objItemKey in pobjRequest blnFile = false intError = 0 'default no error select case pstrAttachmentMethod case "NC", "" objItem = pobjRequest(objItemKey) if isArray(objItem) then 'we've got a file strFilename = objItem(0) 'filename strContentType = objItem(1) 'contentype bsValue = objItem(2) 'value intAttachmentSize = LenB(bsValue) blnFile = true end if case "SAFU" if isObject(pobjRequest(objItemKey)) then set objSAFile = pobjRequest(objItemKey) 'we've got a file strContentType = objSAFile.ContentType strFilename = objSAFile.UserFilename intAttachmentSize = objSAFile.TotalBytes blnFile = true end if case else call RaiseError(STR_ERROR_UNKNOWN_UPLOAD_METHOD & " " & pstrAttachmentMethod) end select if blnFile then strFileName = Right(strFileName,Len(strFileName)-InstrRev(strFileName,"\")) 'only take the actual filename and not the path. if Len(strFilename)=0 then intError = -1 elseif (pintMaxSize>0) and (intAttachmentSize>(pintMaxSize*1024)) then intError = -2 elseif intAttachmentSize=0 then intError = -3 elseif len(pstrExtensionsAllowed)>0 then 'check that the file extention is allowed if InstrRev(strFilename, ".") = 0 then intError = -4 'no dot else strExtension = LCase(Mid(strFilename, InstrRev(strFilename, "."))) 'get file extension blnAllowedExt = (InStr(pstrExtensionsAllowed, strExtension)>0) if not blnAllowedExt then intError = -4 end if end if end if redim preserve aError(UBound(aError)+1) aError(UBound(aError)) = intError end if ' blnFile next CheckAttachments = aError end function %>