Back to index

moin  1.9.0~rc2
Public Member Functions
fckcommands.UploadFileCommandMixin Class Reference
Inheritance diagram for fckcommands.UploadFileCommandMixin:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def uploadFile

Detailed Description

Definition at line 130 of file fckcommands.py.


Member Function Documentation

def fckcommands.UploadFileCommandMixin.uploadFile (   self,
  resourceType,
  currentFolder 
)
Purpose: command to upload files to server (same as FileUpload)

Definition at line 131 of file fckcommands.py.

00131 
00132        def uploadFile(self, resourceType, currentFolder):
00133               """
00134               Purpose: command to upload files to server (same as FileUpload)
00135               """
00136               errorNo = 0
00137               if self.request.has_key("NewFile"):
00138                      # newFile has all the contents we need
00139                      newFile = self.request.get("NewFile", "")
00140                      # Get the file name
00141                      newFileName = newFile.filename
00142                      newFileName = sanitizeFileName( newFileName )
00143                      newFileNameOnly = removeExtension(newFileName)
00144                      newFileExtension = getExtension(newFileName).lower()
00145                      allowedExtensions = Config.AllowedExtensions[resourceType]
00146                      deniedExtensions = Config.DeniedExtensions[resourceType]
00147 
00148                      if (allowedExtensions):
00149                             # Check for allowed
00150                             isAllowed = False
00151                             if (newFileExtension in allowedExtensions):
00152                                    isAllowed = True
00153                      elif (deniedExtensions):
00154                             # Check for denied
00155                             isAllowed = True
00156                             if (newFileExtension in deniedExtensions):
00157                                    isAllowed = False
00158                      else:
00159                             # No extension limitations
00160                             isAllowed = True
00161 
00162                      if (isAllowed):
00163                             # Upload to operating system
00164                             # Map the virtual path to the local server path
00165                             currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
00166                             i = 0
00167                             while (True):
00168                                    newFilePath = os.path.join (currentFolderPath,newFileName)
00169                                    if os.path.exists(newFilePath):
00170                                           i += 1
00171                                           newFileName = "%s(%d).%s" % (
00172                                                         newFileNameOnly, i, newFileExtension
00173                                                         )
00174                                           errorNo= 201 # file renamed
00175                                    else:
00176                                           # Read file contents and write to the desired path (similar to php's move_uploaded_file)
00177                                           fout = file(newFilePath, 'wb')
00178                                           while (True):
00179                                                  chunk = newFile.file.read(100000)
00180                                                  if not chunk: break
00181                                                  fout.write (chunk)
00182                                           fout.close()
00183 
00184                                           if os.path.exists ( newFilePath ):
00185                                                  doChmod = False
00186                                                  try:
00187                                                         doChmod = Config.ChmodOnUpload
00188                                                         permissions = Config.ChmodOnUpload
00189                                                  except AttributeError: #ChmodOnUpload undefined
00190                                                         doChmod = True
00191                                                         permissions = 0755
00192                                                  if ( doChmod ):
00193                                                         oldumask = os.umask(0)
00194                                                         os.chmod( newFilePath, permissions )
00195                                                         os.umask( oldumask )
00196 
00197                                           newFileUrl = combinePaths(self.webUserFilesFolder, currentFolder) + newFileName
00198 
00199                                           return self.sendUploadResults( errorNo , newFileUrl, newFileName )
00200                      else:
00201                             return self.sendUploadResults( errorNo = 202, customMsg = "" )
00202               else:
00203                      return self.sendUploadResults( errorNo = 202, customMsg = "No File" )

Here is the call graph for this function:


The documentation for this class was generated from the following file: