(self, resourceType, currentFolder)
Purpose: command to upload files to server (same as FileUpload)
Purpose: command to upload files to server (same as FileUpload)
Purpose : command to upload files to server ( same as FileUpload )
def uploadFile(self, resourceType, currentFolder):
		"""
		Purpose: command to upload files to server (same as FileUpload)
		"""
		errorNo = 0
		if self.request.has_key("NewFile"):
			# newFile has all the contents we need
			newFile = self.request.get("NewFile", "")
			# Get the file name
			newFileName = newFile.filename
			newFileName = sanitizeFileName( newFileName )
			newFileNameOnly = removeExtension(newFileName)
			newFileExtension = getExtension(newFileName).lower()
			allowedExtensions = Config.AllowedExtensions[resourceType]
			deniedExtensions = Config.DeniedExtensions[resourceType]

			if (allowedExtensions):
				# Check for allowed
				isAllowed = False
				if (newFileExtension in allowedExtensions):
					isAllowed = True
			elif (deniedExtensions):
				# Check for denied
				isAllowed = True
				if (newFileExtension in deniedExtensions):
					isAllowed = False
			else:
				# No extension limitations
				isAllowed = True

			if (isAllowed):
				# Upload to operating system
				# Map the virtual path to the local server path
				currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
				i = 0
				while (True):
					newFilePath = os.path.join (currentFolderPath,newFileName)
					if os.path.exists(newFilePath):
						i += 1
						newFileName = "%s(%04d).%s" % (
								newFileNameOnly, i, newFileExtension
								)
						errorNo= 201 # file renamed
					else:
						# Read file contents and write to the desired path (similar to php's move_uploaded_file)
						fout = file(newFilePath, 'wb')
						while (True):
							chunk = newFile.file.read(100000)
							if not chunk: break
							fout.write (chunk)
						fout.close()

						if os.path.exists ( newFilePath ):
							doChmod = False
							try:
								doChmod = Config.ChmodOnUpload
								permissions = Config.ChmodOnUpload
							except AttributeError: #ChmodOnUpload undefined
								doChmod = True
								permissions = 0755
							if ( doChmod ):
								oldumask = os.umask(0)
								os.chmod( newFilePath, permissions )
								os.umask( oldumask )

						newFileUrl = self.webUserFilesFolder + currentFolder + newFileName

						return self.sendUploadResults( errorNo , newFileUrl, newFileName )
			else:
				return self.sendUploadResults( errorNo = 203, customMsg = "Extension not allowed" )
		else:
			return self.sendUploadResults( errorNo = 202, customMsg = "No File" )
def uploadFile ( self , resourceType , currentFolder ) : errorNo = 0 if self . request . has_key ( "NewFile" ) : # newFile has all the contents we need newFile = self . request . get ( "NewFile" , "" ) # Get the file name newFileName = newFile . filename newFileName = sanitizeFileName ( newFileName ) newFileNameOnly = removeExtension ( newFileName ) newFileExtension = getExtension ( newFileName ) . lower ( ) allowedExtensions = Config . AllowedExtensions [ resourceType ] deniedExtensions = Config . DeniedExtensions [ resourceType ] if ( allowedExtensions ) : # Check for allowed isAllowed = False if ( newFileExtension in allowedExtensions ) : isAllowed = True elif ( deniedExtensions ) : # Check for denied isAllowed = True if ( newFileExtension in deniedExtensions ) : isAllowed = False else : # No extension limitations isAllowed = True if ( isAllowed ) : # Upload to operating system # Map the virtual path to the local server path currentFolderPath = mapServerFolder ( self . userFilesFolder , currentFolder ) i = 0 while ( True ) : newFilePath = os . path . join ( currentFolderPath , newFileName ) if os . path . exists ( newFilePath ) : i += 1 newFileName = "%s(%04d).%s" % ( newFileNameOnly , i , newFileExtension ) errorNo = 201 # file renamed else : # Read file contents and write to the desired path (similar to php's move_uploaded_file) fout = file ( newFilePath , 'wb' ) while ( True ) : chunk = newFile . file . read ( 100000 ) if not chunk : break fout . write ( chunk ) fout . close ( ) if os . path . exists ( newFilePath ) : doChmod = False try : doChmod = Config . ChmodOnUpload permissions = Config . ChmodOnUpload except AttributeError : #ChmodOnUpload undefined doChmod = True permissions = 0755 if ( doChmod ) : oldumask = os . umask ( 0 ) os . chmod ( newFilePath , permissions ) os . umask ( oldumask ) newFileUrl = self . webUserFilesFolder + currentFolder + newFileName return self . sendUploadResults ( errorNo , newFileUrl , newFileName ) else : return self . sendUploadResults ( errorNo = 203 , customMsg = "Extension not allowed" ) else : return self . sendUploadResults ( errorNo = 202 , customMsg = "No File" )