Logo Search packages:      
Sourcecode: fckeditor version File versions  Download package

def fckcommands::UploadFileCommandMixin::uploadFile (   self,
  resourceType,
  currentFolder 
) [inherited]

Purpose: command to upload files to server (same as FileUpload)

Definition at line 118 of file fckcommands.py.

                                                       :
            """
            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 ):
                                          oldumask = os.umask(0) 
                                          os.chmod( newFilePath, 0755 ) 
                                          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" )
                  return self.sendUploadResults( errorNo = 202, customMsg = "No File" )


Generated by  Doxygen 1.6.0   Back to index