[BUGFIX] Fix 1-2-3(-4) wizard
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_extfilefunc.php
index 2124515..467734e 100644 (file)
  *
  * Revised for TYPO3 3.6 May/2004 by Kasper Skårhøj
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *  105: class t3lib_extFileFunctions extends t3lib_basicFileFunctions
- *  151:        function start($fileCmds)
- *  181:        function init_actionPerms($setup)
- *  213:        function processData()
- *  270:        function printLogErrorMessages($redirect='')
- *  328:        function findRecycler($theFile)
- *  357:        function writeLog($action,$error,$details_nr,$details,$data)
- *
- *                       SECTION: File operation functions
- *  384:        function func_delete($cmds)
- *  451:        function func_copy($cmds)
- *  542:        function func_move($cmds)
- *  637:        function func_rename($cmds)
- *  683:        function func_newfolder($cmds)
- *  713:        function func_newfile($cmds)
- *  750:        function func_edit($cmds)
- *  782:        function func_upload($cmds)
- *  821:        function func_unzip($cmds)
- *
- * TOTAL FUNCTIONS: 15
- * (This index is automatically created/updated by the extension "extdeveval")
- *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 
-
 /**
  * Contains functions for performing file operations like copying, pasting, uploading, moving, deleting etc. through the TCE
  * Extending class to class t3lib_basicFileFunctions.
@@ -75,7 +46,7 @@
  *
  * $filemounts         (see basicFileFunctions)
  * $f_ext        (see basicFileFunctions)
- *      ... All fileoperations must be within the filemount-paths. Further the fileextension MUST validate true with the f_ext array
+ *      ... All fileoperations must be within the filemount-paths. Further the fileextension MUST validate TRUE with the f_ext array
  *
  * The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!!
  * You are allowed to copy/move folders within the same 'space' (web/ftp).
@@ -86,7 +57,7 @@
  * You should never mount a ftp_space 'below' the webspace so that it reaches into the webspace. This is because if somebody unzips a zip-file in the ftp-space so that it reaches out into the webspace this will be a violation of the safety
  * For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
@@ -94,13 +65,15 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
 
                // External static variables:
                // Notice; some of these are overridden in the start() method with values from $GLOBALS['TYPO3_CONF_VARS']['BE']
-       var $maxCopyFileSize = 10000; // max copy size (kb) for files
-       var $maxMoveFileSize = 10000; // max move size (kb) for files
-       var $maxUploadFileSize = 10000; // max upload size (kb) for files. Remember that PHP has an inner limit often set to 2 MB
-       var $unzipPath = ''; // Path to unzip-program (with trailing '/')
-       var $dontCheckForUnique = 0; // If set, the uploaded files will overwrite existing files.
-
-       var $actionPerms = Array( // This array is self-explaning (look in the class below). It grants access to the functions. This could be set from outside in order to enabled functions to users. See also the function init_actionPerms() which takes input directly from the user-record
+               // Path to unzip-program (with trailing '/')
+       var $unzipPath = '';
+               // If set, the uploaded files will overwrite existing files.
+       var $dontCheckForUnique = 0;
+
+               // This array is self-explaning (look in the class below).
+               // It grants access to the functions. This could be set from outside in order to enabled functions to users.
+               // See also the function init_actionPerms() which takes input directly from the user-record
+       var $actionPerms = array(
                'deleteFile' => 0, // Deleting files physically
                'deleteFolder' => 0, // Deleting foldes physically
                'deleteFolderRecursively' => 0, // normally folders are deleted by the PHP-function rmdir(), but with this option a user deletes with 'rm -Rf ....' which is pretty wild!
@@ -117,43 +90,52 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
                'renameFolder' => 0
        );
 
-       var $recyclerFN = '_recycler_'; // This is regarded to be the recycler folder
-       var $useRecycler = 1; // 0 = no, 1 = if available, 2 = always
+               // This is regarded to be the recycler folder
+       var $recyclerFN = '_recycler_';
 
-               // Internal, static:
-       var $PHPFileFunctions = 0; // If set, all fileoperations are done by the default PHP-functions. This is necessary under windows! On UNIX the system commands by exec() can be used unless safe_mode is enabled
-       var $dont_use_exec_commands = 0; // This is necessary under windows!
+       /**
+        * Whether to use recycler (0 = no, 1 = if available, 2 = always)
+        *
+        * @var integer
+        * @deprecated since TYPO3 6.0
+        */
+       var $useRecycler = 1;
 
-               // Internal, dynamic:
-       var $internalUploadMap = array(); // Will contain map between upload ID and the final filename
+               // Internal, dynamic
+               // Will contain map between upload ID and the final filename
+       var $internalUploadMap = array();
 
        var $lastError = '';
 
+       /**
+        * @var array
+        */
+       protected $fileCmdMap;
+
+       /**
+        * The File Factory
+        *
+        * @var t3lib_file_Factory
+        */
+       protected $fileFactory;
 
        /**
         * Initialization of the class
         *
-        * @param       array           The $file array with the commands to execute. See "TYPO3 Core API" document
-        * @return      void
+        * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
+        * @return void
         */
        function start($fileCmds) {
 
-                       // Configure settings from TYPO3_CONF_VARS:
-               if (TYPO3_OS == 'WIN' || $GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
-                       $this->PHPFileFunctions = 1;
-                       $this->dont_use_exec_commands = 1;
-               } else {
-                       $this->PHPFileFunctions = $GLOBALS['TYPO3_CONF_VARS']['BE']['usePHPFileFunctions'];
+               $unzipPath = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path']);
+               if (substr($unzipPath, -1) !== '/' && is_dir($unzipPath)) {
+                               // Make sure the path ends with a slash
+                       $unzipPath.= '/';
                }
+               $this->unzipPath = $unzipPath;
 
-               $this->unzipPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'];
-
-               $maxFileSize = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize']);
-               if ($maxFileSize > 0) {
-                       $this->maxCopyFileSize = $maxFileSize;
-                       $this->maxMoveFileSize = $maxFileSize;
-               }
-               $this->maxUploadFileSize = t3lib_div::getMaxUploadFileSize();
+                       // Initialize Object Factory
+               $this->fileFactory = t3lib_file_Factory::getInstance();
 
                        // Initializing file processing commands:
                $this->fileCmdMap = $fileCmds;
@@ -163,11 +145,12 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
         * Sets up permission to perform file/directory operations.
         * See below or the be_user-table for the significance of the various bits in $setup.
         *
-        * @param       integer         File permission integer from BE_USER OR'ed with permissions of back-end groups this user is a member of
-        * @return      void
+        * @param integer $setup File permission integer from BE_USER OR'ed with permissions of back-end groups this user is a member of
+        * @return void
         */
        function init_actionPerms($setup) {
-               if (($setup & 1) == 1) { // Files: Upload,Copy,Move,Delete,Rename
+                       // Files: Upload,Copy,Move,Delete,Rename
+               if (($setup & 1) == 1) {
                        $this->actionPerms['uploadFile'] = 1;
                        $this->actionPerms['copyFile'] = 1;
                        $this->actionPerms['moveFile'] = 1;
@@ -176,19 +159,23 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
                        $this->actionPerms['editFile'] = 1;
                        $this->actionPerms['newFile'] = 1;
                }
-               if (($setup & 2) == 2) { // Files: Unzip
+                       // Files: Unzip
+               if (($setup & 2) == 2) {
                        $this->actionPerms['unzipFile'] = 1;
                }
-               if (($setup & 4) == 4) { // Directory: Move,Delete,Rename,New
+                       // Directory: Move,Delete,Rename,New
+               if (($setup & 4) == 4) {
                        $this->actionPerms['moveFolder'] = 1;
                        $this->actionPerms['deleteFolder'] = 1;
                        $this->actionPerms['renameFolder'] = 1;
                        $this->actionPerms['newFolder'] = 1;
                }
-               if (($setup & 8) == 8) { // Directory: Copy
+                       // Directory: Copy
+               if (($setup & 8) == 8) {
                        $this->actionPerms['copyFolder'] = 1;
                }
-               if (($setup & 16) == 16) { // Directory: Delete recursively (rm -Rf)
+                       // Directory: Delete recursively (rm -Rf)
+               if (($setup & 16) == 16) {
                        $this->actionPerms['deleteFolderRecursively'] = 1;
                }
        }
@@ -196,9 +183,9 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
        /**
         * Processing the command array in $this->fileCmdMap
         *
-        * @return      mixed   false, if the file functions were not initialized
-        *                                      otherwise returns an array of all the results that are returned
-        *                                      from each command, separated in each action.
+        * @return mixed FALSE, if the file functions were not initialized
+        *                              otherwise returns an array of all the results that are returned
+        *                              from each command, separated in each action.
         */
        function processData() {
                $result = array();
@@ -285,19 +272,18 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
        /**
         * Adds log error messages from the operations of this script instance to the FlashMessageQueue
         *
-        * @param       string          Redirect URL (for creating link in message)
-        * @return      void
+        * @param string $redirect Redirect URL (for creating link in message)
+        * @return void
         */
        function printLogErrorMessages($redirect = '') {
                $this->getErrorMessages();
        }
 
-
        /**
         * Adds log error messages from the previous file operations of this script instance
         * to the FlashMessageQueue
         *
-        * @return      void
+        * @return void
         */
        function getErrorMessages() {
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
@@ -305,7 +291,7 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
                        'sys_log',
                                'type = 2 AND userid = ' . intval($GLOBALS['BE_USER']->user['uid'])
                                                . ' AND tstamp=' . intval($GLOBALS['EXEC_TIME'])
-                                               . ' AND error != 0'
+                                               . ' AND error<>0'
                );
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $logData = unserialize($row['log_data']);
@@ -322,21 +308,26 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
        }
 
-
        /**
         * Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.
         * If a folder in the tree happens to be a _recycler_-folder (which means that we're deleting something inside a _recycler_-folder) this is ignored
         *
-        * @param       string          Takes a valid Path ($theFile)
-        * @return      string          Returns the path (without trailing slash) of the closest recycle-folder if found. Else false.
+        * @param string $theFile Takes a valid Path ($theFile)
+        * @return string Returns the path (without trailing slash) of the closest recycle-folder if found. Else FALSE.
+        *
+        * @todo To be put in Storage with a better concept
+        * @deprecated since TYPO3 6.0, use t3lib_file_Storage method instead
         */
        function findRecycler($theFile) {
+               t3lib_div::logDeprecatedFunction();
+
                if ($this->isPathValid($theFile)) {
                        $theFile = $this->cleanDirectoryName($theFile);
                        $fI = t3lib_div::split_fileref($theFile);
                        $c = 0;
-                       while ($this->checkPathAgainstMounts($fI['path']) && $c < 20) {
+                               // !!! Method has been put in the storage, can be saftely removed
                                $rDir = $fI['path'] . $this->recyclerFN;
+                       while ($this->checkPathAgainstMounts($fI['path']) && $c < 20) {
                                if (@is_dir($rDir) && $this->recyclerFN != $fI['file']) {
                                        return $rDir;
                                }
@@ -351,23 +342,23 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
        /**
         * Logging file operations
         *
-        * @param       integer         The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
-        * @param       integer         The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
-        * @param       integer         This number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
-        * @param       string          This is the default, raw error message in english
-        * @param       array           Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
-        * @return      void
+        * @param integer $action The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
+        * @param integer $error The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
+        * @param integer $details_nr This number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
+        * @param string $details This is the default, raw error message in english
+        * @param array $data Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
+        * @return void
         * @see class.t3lib_userauthgroup.php
         */
        function writeLog($action, $error, $details_nr, $details, $data) {
-               $type = 2; // Type value for tce_file.php
+                       // Type value for tce_file.php
+               $type = 2;
                if (is_object($GLOBALS['BE_USER'])) {
                        $GLOBALS['BE_USER']->writelog($type, $action, $error, $details_nr, $details, $data);
                }
                $this->lastError = vsprintf($details, $data);
        }
 
-
        /*************************************
         *
         * File operation functions
@@ -377,604 +368,557 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
        /**
         * Deleting files and folders (action=4)
         *
-        * @param       array           $cmds['data'] is the file/folder to delete
-        * @return      boolean         Returns true upon success
+        * @param array $cmds $cmds['data'] is the file/folder to delete
+        * @return boolean Returns TRUE upon success
         */
        function func_delete($cmds) {
+               $result = FALSE;
+
                if (!$this->isInit) {
-                       return FALSE;
+                       return $result;
                }
 
-                       // Checking path:
-               $theFile = $cmds['data'];
-               if (!$this->isPathValid($theFile)) {
-                       $this->writelog(4, 2, 101, 'Target "%s" had invalid path (".." and "//" is not allowed in path).', Array($theFile));
-                       return FALSE;
-               }
+                       // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
+                       // for backwards compatibility: the combined file identifier was the path+filename
+               $fileObject = $this->getFileObject($cmds['data']);
 
-                       // Recycler moving or not?
-               if ($this->useRecycler && $recyclerPath = $this->findRecycler($theFile)) {
-                               // If a recycler is found, the deleted items is moved to the recycler and not just deleted.
-                       $newCmds = Array();
-                       $newCmds['data'] = $theFile;
-                       $newCmds['target'] = $recyclerPath;
-                       $newCmds['altName'] = 1;
-                       $this->func_move($newCmds);
-                       $this->writelog(4, 0, 4, 'Item "%s" moved to recycler at "%s"', Array($theFile, $recyclerPath));
-                       return TRUE;
-               } elseif ($this->useRecycler != 2) { // if $this->useRecycler==2 then we cannot delete for real!!
-                       if (@is_file($theFile)) { // If we are deleting a file...
-                               if ($this->actionPerms['deleteFile']) {
-                                       if ($this->checkPathAgainstMounts($theFile)) {
-                                               if (@unlink($theFile)) {
-                                                       $this->writelog(4, 0, 1, 'File "%s" deleted', Array($theFile));
-                                                       return TRUE;
-                                               } else {
-                                                       $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', Array($theFile));
-                                               }
-                                       } else {
-                                               $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', Array($theFile));
-                                       }
-                               } else {
-                                       $this->writelog(4, 1, 112, 'You are not allowed to delete files', '');
-                               }
-                               // FINISHED deleting file
-
-                       } elseif (@is_dir($theFile)) { // if we're deleting a folder
-                               if ($this->actionPerms['deleteFolder']) {
-                                       $theFile = $this->is_directory($theFile);
-                                       if ($theFile) {
-                                               if ($this->checkPathAgainstMounts($theFile)) { // I choose not to append '/' to $theFile here as this will prevent us from deleting mounts!! (which makes sense to me...)
-                                                       if ($this->actionPerms['deleteFolderRecursively']) {
-                                                               if (t3lib_div::rmdir($theFile, TRUE)) {
-                                                                       $this->writelog(4, 0, 2, 'Directory "%s" deleted recursively!', Array($theFile));
-                                                                       return TRUE;
-                                                               } else {
-                                                                       $this->writelog(4, 2, 119, 'Directory "%s" WAS NOT deleted recursively! Write-permission problem?', Array($theFile));
-                                                               }
-                                                       } else {
-                                                               if (@rmdir($theFile)) {
-                                                                       $this->writelog(4, 0, 3, 'Directory "%s" deleted', Array($theFile));
-                                                                       return TRUE;
-                                                               } else {
-                                                                       $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', Array($theFile));
-                                                               }
-                                                       }
-                                               } else {
-                                                       $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', Array($theFile));
-                                               }
-                                       } else {
-                                               $this->writelog(4, 2, 122, 'Target seemed not to be a directory! (Shouldn\'t happen here!)', '');
+                       // @todo implement the recycler feature which has been removed from the original implementation
+
+                       // Copies the file
+               if ($fileObject instanceof t3lib_file_File) {
+                       $refIndexRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               '*',
+                               'sys_refindex',
+                               "ref_table='sys_file' AND ref_uid=" . $fileObject->getUid()
+                       );
+
+                       if (count($refIndexRecords) > 0) {
+                               $shortcutContent = array();
+
+                               foreach ($refIndexRecords as $row) {
+                                       $shortcutRecord = NULL;
+                                       $shortcutRecord = t3lib_BEfunc::getRecord($row['tablename'], $row['recuid']);
+                                       if (is_array($shortcutRecord) && $row['tablename'] !== 'sys_file_reference') {
+                                               $icon = t3lib_iconWorks::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
+
+                                               $onClick = 'showClickmenu("' . $row['tablename'] . '", "' . $row['recuid'] . '", "1", "+info,history,edit,delete", "|", "");return false;';
+                                               $shortcutContent[] = '<a href="#" oncontextmenu="' . htmlspecialchars($onClick) . '" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' .
+                                                       htmlspecialchars(t3lib_BEfunc::getRecordTitle($row['tablename'], $shortcutRecord) . '  [' . t3lib_BEfunc::getRecordPath($shortcutRecord['pid'], '', 80) . ']');
                                        }
-                               } else {
-                                       $this->writelog(4, 1, 123, 'You are not allowed to delete directories', '');
                                }
-                               // FINISHED copying directory
+
+                               $out = '<p>The file cannot be deleted since it is still used at the following places:<br />' .
+                                               implode('<br />', $shortcutContent) . '</p>';
+
+                               $flashMessage = t3lib_div::makeInstance(
+                                       't3lib_flashMessage',
+                                       $out,
+                                       'File not deleted',
+                                       t3lib_FlashMessage::WARNING,
+                                       TRUE
+                               );
+                               t3lib_FlashMessageQueue::addMessage($flashMessage);
+                               return;
 
                        } else {
-                               $this->writelog(4, 2, 130, 'The item was not a file or directory! "%s"', Array($theFile));
+                               try {
+                                       $result = $fileObject->delete();
+                               } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                                       $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
+                               } catch (t3lib_file_exception_NotInMountPointException $e) {
+                                       $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
+                               } catch (RuntimeException $e) {
+                                       $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
+                               }
+                                       // Log success
+                               $this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
                        }
+                       // Working on a folder
                } else {
-                       $this->writelog(4, 1, 131, 'No recycler found!', '');
+                       try {
+                               /** @var $fileObject t3lib_file_FolderInterface */
+                               $result = $fileObject->delete(TRUE);
+                       } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                               $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
+                       } catch (t3lib_file_exception_NotInMountPointException $e) {
+                               $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
+                       }
+
+                               // Log success
+                       $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
+               }
+
+               return $result;
+       }
+
+       /**
+        * Gets a File or a Folder object from an identifier [storage]:[fileId]
+        *
+        * @param string $identifier
+        * @return t3lib_file_Folder|t3lib_file_File
+        */
+       protected function getFileObject($identifier) {
+               $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
+
+               if (!is_object($object)) {
+                       throw new t3lib_file_exception_InvalidFileException(
+                               'The item ' . $identifier . ' was not a file or directory!!',
+                               1320122453
+                       );
                }
+
+               return $object;
        }
 
        /**
         * Copying files and folders (action=2)
         *
-        * @param       array           $cmds['data'] is the file/folder to copy. $cmds['target'] is the path where to copy to. $cmds['altName'] (boolean): If set, another filename is found in case the target already exists
-        * @return      string          Returns the new filename upon success
+        * $cmds['data'] (string): The file/folder to copy
+        * + example "4:mypath/tomyfolder/myfile.jpg")
+        * + for backwards compatibility: the identifier was the path+filename
+        * $cmds['target'] (string): The path where to copy to.
+        * + example "2:targetpath/targetfolder/"
+        * $cmds['altName'] (string): Use an alternative name if the target already exists
+        *
+        * @param array $cmds Command details as described above
+        * @return t3lib_file_File
         */
-       function func_copy($cmds) {
+       protected function func_copy($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
 
-                       // Initialize and check basic conditions:
-               $theFile = $cmds['data'];
-               $theDest = $this->is_directory($cmds['target']); // Clean up destination directory
-               $altName = $cmds['altName'];
-               if (!$theDest) {
-                       $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', Array($cmds['target']));
-                       return FALSE;
-               }
-               if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
-                       $this->writelog(2, 2, 101, 'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"', Array($theFile, $theDest));
+               $sourceFileObject = $this->getFileObject($cmds['data']);
+               /** @var $targetFolderObject t3lib_file_Folder */
+               $targetFolderObject = $this->getFileObject($cmds['target']);
+
+                       // Basic check
+               if (!($targetFolderObject instanceof t3lib_file_Folder)) {
+                       $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
                        return FALSE;
                }
 
-                       // Processing of file or directory.
-               if (@is_file($theFile)) { // If we are copying a file...
-                       if ($this->actionPerms['copyFile']) {
-                               if (filesize($theFile) < ($this->maxCopyFileSize * 1024)) {
-                                       $fI = t3lib_div::split_fileref($theFile);
-                                       if ($altName) { // If altName is set, we're allowed to create a new filename if the file already existed
-                                               $theDestFile = $this->getUniqueName($fI['file'], $theDest);
-                                               $fI = t3lib_div::split_fileref($theDestFile);
-                                       } else {
-                                               $theDestFile = $theDest . '/' . $fI['file'];
-                                       }
-                                       if ($theDestFile && !file_exists($theDestFile)) {
-                                               if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
-                                                       if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
-                                                               if ($this->PHPFileFunctions) {
-                                                                       copy($theFile, $theDestFile);
-                                                               } else {
-                                                                       $cmd = 'cp "' . $theFile . '" "' . $theDestFile . '"';
-                                                                       t3lib_utility_Command::exec($cmd);
-                                                               }
-                                                               t3lib_div::fixPermissions($theDestFile);
-                                                               clearstatcache();
-                                                               if (@is_file($theDestFile)) {
-                                                                       $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', Array($theFile, $theDestFile));
-                                                                       return $theDestFile;
-                                                               } else {
-                                                                       $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', Array($theFile, $theDestFile));
-                                                               }
-                                                       } else  {
-                                                               $this->writelog(2, 1, 110, 'Target or destination was not within your mountpoints! T="%s", D="%s"', Array($theFile, $theDestFile));
-                                                       }
-                                               } else {
-                                                       $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', Array($fI['file'], $theDest . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(2, 1, 112, 'File "%s" already exists!', Array($theDestFile));
-                                       }
-                               } else {
-                                       $this->writelog(2, 1, 113, 'File "%s" exceeds the size-limit of %s bytes', Array($theFile, $this->maxCopyFileSize * 1024));
-                               }
-                       } else {
+                       // If this is TRUE, we append _XX to the file name if
+               $appendSuffixOnConflict = (string) $cmds['altName'];
+               $resultObject = NULL;
+
+                       // Copying the file
+               if ($sourceFileObject instanceof t3lib_file_File) {
+                       try {
+                               $conflictMode = ($appendSuffixOnConflict !== '') ? 'renameNewFile' : 'cancel';
+                               $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
                                $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
+                       } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                               $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_IllegalFileExtensionException $e) {
+                               $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                               $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                        }
-                       // FINISHED copying file
-
-               } elseif (@is_dir($theFile) && !$this->dont_use_exec_commands) { // if we're copying a folder
-                       if ($this->actionPerms['copyFolder']) {
-                               $theFile = $this->is_directory($theFile);
-                               if ($theFile) {
-                                       $fI = t3lib_div::split_fileref($theFile);
-                                       if ($altName) { // If altName is set, we're allowed to create a new filename if the file already existed
-                                               $theDestFile = $this->getUniqueName($fI['file'], $theDest);
-                                               $fI = t3lib_div::split_fileref($theDestFile);
-                                       } else {
-                                               $theDestFile = $theDest . '/' . $fI['file'];
-                                       }
-                                       if ($theDestFile && !file_exists($theDestFile)) {
-                                               if (!t3lib_div::isFirstPartOfStr($theDestFile . '/', $theFile . '/')) { // Check if the one folder is inside the other or on the same level... to target/dest is the same?
-                                                       if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile) == $this->is_webPath($theFile)) { // no copy of folders between spaces
-                                                               if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
-                                                                       // No way to do this under windows!
-                                                                       $cmd = 'cp -R "' . $theFile . '" "' . $theDestFile . '"';
-                                                                       t3lib_utility_Command::exec($cmd);
-                                                                       clearstatcache();
-                                                                       if (@is_dir($theDestFile)) {
-                                                                               $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', Array($theFile, $theDestFile));
-                                                                               return $theDestFile;
-                                                                       } else {
-                                                                               $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', Array($theFile, $theDestFile));
-                                                                       }
-                                                               } else {
-                                                                       $this->writelog(2, 1, 120, 'Target or destination was not within your mountpoints! T="%s", D="%s"', Array($theFile, $theDestFile));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', Array($theDest . '/'));
-                                                       }
-                                               } else {
-                                                       $this->writelog(2, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', Array($theDestFile . '/', $theFile . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(2, 1, 123, 'Target "%s" already exists!', Array($theDestFile));
-                                       }
-                               } else {
-                                       $this->writelog(2, 2, 124, 'Target seemed not to be a directory! (Shouldn\'t happen here!)', '');
-                               }
-                       } else {
+
+                       $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
+
+               } else { // Else means this is a Folder
+                       $sourceFolderObject = $sourceFileObject;
+
+                       try {
+                               $conflictMode = ($appendSuffixOnConflict !== '') ? 'renameNewFile' : 'cancel';
+                               $resultObject = $sourceFolderObject->copyTo($targetFolderObject, NULL, $conflictMode);
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
                                $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
+                       } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                               $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_InsufficientFolderAccessPermissionsException $e) {
+                               $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_InvalidTargetFolderException $e) {
+                               $this->writelog(2, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_ExistingTargetFolderException $e) {
+                               $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                        }
-                       // FINISHED copying directory
 
-               } else {
-                       $this->writelog(2, 2, 130, 'The item "%s" was not a file or directory!', Array($theFile));
+                       $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                }
+
+               return $resultObject;
        }
 
        /**
         * Moving files and folders (action=3)
         *
-        * @param       array           $cmds['data'] is the file/folder to move. $cmds['target'] is the path where to move to. $cmds['altName'] (boolean): If set, another filename is found in case the target already exists
-        * @return      string          Returns the new filename upon success
+        * $cmds['data'] (string): The file/folder to move
+        * + example "4:mypath/tomyfolder/myfile.jpg")
+        * + for backwards compatibility: the identifier was the path+filename
+        * $cmds['target'] (string): The path where to move to.
+        * + example "2:targetpath/targetfolder/"
+        * $cmds['altName'] (string): Use an alternative name if the target already exists
+        *
+        * @param array $cmds Command details as described above
+        * @return t3lib_file_File
         */
-       function func_move($cmds) {
+       protected function func_move($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
 
-                       // Initialize and check basic conditions:
-               $theFile = $cmds['data'];
-               $theDest = $this->is_directory($cmds['target']); // Clean up destination directory
-               $altName = $cmds['altName'];
-               if (!$theDest) {
-                       $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', Array($cmds['target']));
-                       return FALSE;
-               }
-               if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
-                       $this->writelog(3, 2, 101, 'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"', Array($theFile, $theDest));
+               $sourceFileObject = $this->getFileObject($cmds['data']);
+               $targetFolderObject = $this->getFileObject($cmds['target']);
+
+                       // Basic check
+               if (!($targetFolderObject instanceof t3lib_file_Folder)) {
+                       $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
                        return FALSE;
                }
 
-                       // Processing of file or directory:
-               if (@is_file($theFile)) { // If we are moving a file...
-                       if ($this->actionPerms['moveFile']) {
-                               if (filesize($theFile) < ($this->maxMoveFileSize * 1024)) {
-                                       $fI = t3lib_div::split_fileref($theFile);
-                                       if ($altName) { // If altName is set, we're allowed to create a new filename if the file already existed
-                                               $theDestFile = $this->getUniqueName($fI['file'], $theDest);
-                                               $fI = t3lib_div::split_fileref($theDestFile);
-                                       } else {
-                                               $theDestFile = $theDest . '/' . $fI['file'];
-                                       }
-                                       if ($theDestFile && !file_exists($theDestFile)) {
-                                               if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
-                                                       if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
-                                                               if ($this->PHPFileFunctions) {
-                                                                       @rename($theFile, $theDestFile);
-                                                               } else {
-                                                                       $cmd = 'mv "' . $theFile . '" "' . $theDestFile . '"';
-                                                                       t3lib_utility_Command::exec($cmd);
-                                                               }
-                                                               clearstatcache();
-                                                               if (@is_file($theDestFile)) {
-                                                                       $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', Array($theFile, $theDestFile));
-                                                                       return $theDestFile;
-                                                               } else {
-                                                                       $this->writelog(3, 2, 109, 'File "%s" WAS NOT moved to "%s"! Write-permission problem?', Array($theFile, $theDestFile));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(3, 1, 110, 'Target or destination was not within your mountpoints! T="%s", D="%s"', Array($theFile, $theDestFile));
-                                                       }
-                                               } else {
-                                                       $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', Array($fI['file'], $theDest . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(3, 1, 112, 'File "%s" already exists!', Array($theDestFile));
-                                       }
+               $alternativeName = (string) $cmds['altName'];
+               $resultObject = NULL;
+
+                       // Moving the file
+               if ($sourceFileObject instanceof t3lib_file_File) {
+                       try {
+                               if ($alternativeName !== '') {
+                                               // Don't allow overwriting existing files, but find a new name
+                                       $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
                                } else {
-                                       $this->writelog(3, 1, 113, 'File "%s" exceeds the size-limit of %s bytes', Array($theFile, $this->maxMoveFileSize * 1024));
+                                               // Don't allow overwriting existing files
+                                       $resultObject = $sourceFileObject->moveTo($targetFolderObject, NULL, 'cancel');
                                }
-                       } else {
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
                                $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
+                       } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                               $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_IllegalFileExtensionException $e) {
+                               $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                               $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                        }
-                       // FINISHED moving file
-
-               } elseif (@is_dir($theFile)) { // if we're moving a folder
-                       if ($this->actionPerms['moveFolder']) {
-                               $theFile = $this->is_directory($theFile);
-                               if ($theFile) {
-                                       $fI = t3lib_div::split_fileref($theFile);
-                                       if ($altName) { // If altName is set, we're allowed to create a new filename if the file already existed
-                                               $theDestFile = $this->getUniqueName($fI['file'], $theDest);
-                                               $fI = t3lib_div::split_fileref($theDestFile);
-                                       } else {
-                                               $theDestFile = $theDest . '/' . $fI['file'];
-                                       }
-                                       if ($theDestFile && !file_exists($theDestFile)) {
-                                               if (!t3lib_div::isFirstPartOfStr($theDestFile . '/', $theFile . '/')) { // Check if the one folder is inside the other or on the same level... to target/dest is the same?
-                                                       if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile) == $this->is_webPath($theFile)) { // // no moving of folders between spaces
-                                                               if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
-                                                                       if ($this->PHPFileFunctions) {
-                                                                               @rename($theFile, $theDestFile);
-                                                                       } else {
-                                                                               $cmd = 'mv "' . $theFile . '" "' . $theDestFile . '"';
-                                                                               $errArr = array();
-                                                                               t3lib_utility_Command::exec($cmd, $errArr);
-                                                                       }
-                                                                       clearstatcache();
-                                                                       if (@is_dir($theDestFile)) {
-                                                                               $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', Array($theFile, $theDestFile));
-                                                                               return $theDestFile;
-                                                                       } else {
-                                                                               $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', Array($theFile, $theDestFile));
-                                                                       }
-                                                               } else {
-                                                                       $this->writelog(3, 1, 120, 'Target or destination was not within your mountpoints! T="%s", D="%s"', Array($theFile, $theDestFile));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', Array($theDest . '/'));
-                                                       }
-                                               } else {
-                                                       $this->writelog(3, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', Array($theDestFile . '/', $theFile . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(3, 1, 123, 'Target "%s" already exists!', Array($theDestFile));
-                                       }
+
+                       $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
+
+               } else { // Else means this is a Folder
+                       $sourceFolderObject = $sourceFileObject;
+
+                       try {
+                               if ($alternativeName !== '') {
+                                               // Don't allow overwriting existing files, but find a new name
+                                       $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
                                } else {
-                                       $this->writelog(3, 2, 124, 'Target seemed not to be a directory! (Shouldn\'t happen here!)', '');
+                                               // Don't allow overwriting existing files
+                                       $resultObject = $sourceFolderObject->moveTo($targetFolderObject, NULL, 'renameNewFile');
                                }
-                       } else {
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
                                $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
+                       } catch (t3lib_file_exception_InsufficientFileAccessPermissionsException $e) {
+                               $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_InsufficientFolderAccessPermissionsException $e) {
+                               $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_InvalidTargetFolderException $e) {
+                               $this->writelog(3, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_ExistingTargetFolderException $e) {
+                               $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                        }
-                       // FINISHED moving directory
 
-               } else {
-                       $this->writelog(3, 2, 130, 'The item "%s" was not a file or directory!', Array($theFile));
+                       $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
                }
+
+               return $resultObject;
        }
 
        /**
         * Renaming files or foldes (action=5)
         *
-        * @param       array           $cmds['data'] is the new name. $cmds['target'] is the target (file or dir).
-        * @return      string          Returns the new filename upon success
+        * $cmds['data'] (string): The file/folder to copy
+        * + example "4:mypath/tomyfolder/myfile.jpg")
+        * + for backwards compatibility: the identifier was the path+filename
+        * $cmds['target'] (string): New name of the file/folder
+        *
+        * @param array $cmds Command details as described above
+        * @return t3lib_file_File Returns the new file upon success
         */
        function func_rename($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
 
-               $theNewName = $this->cleanFileName($cmds['data']);
-               if ($theNewName) {
-                       if ($this->checkFileNameLen($theNewName)) {
-                               $theTarget = $cmds['target'];
-                               $type = filetype($theTarget);
-                               if ($type == 'file' || $type == 'dir') { // $type MUST BE file or dir
-                                       $fileInfo = t3lib_div::split_fileref($theTarget); // Fetches info about path, name, extention of $theTarget
-                                       if ($fileInfo['file'] != $theNewName) { // The name should be different from the current. And the filetype must be allowed
-                                               $theRenameName = $fileInfo['path'] . $theNewName;
-                                               if ($this->checkPathAgainstMounts($fileInfo['path'])) {
-                                                       if (!file_exists($theRenameName)) {
-                                                               if ($type == 'file') {
-                                                                       if ($this->actionPerms['renameFile']) {
-                                                                               $fI = t3lib_div::split_fileref($theRenameName);
-                                                                               if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
-                                                                                       if (@rename($theTarget, $theRenameName)) {
-                                                                                               $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', Array($fileInfo['file'], $theNewName));
-                                                                                               return $theRenameName;
-                                                                                       } else {
-                                                                                               $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', Array($theTarget, $fileInfo['path']));
-                                                                                       }
-                                                                               } else {
-                                                                                       $this->writelog(5, 1, 101, 'Extension of file name "%s" was not allowed!', Array($fI['file']));
-                                                                               }
-                                                                       } else {
-                                                                               $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
-                                                                       }
-                                                               } elseif ($type == 'dir') {
-                                                                       if ($this->actionPerms['renameFolder']) {
-                                                                               if (@rename($theTarget, $theRenameName)) {
-                                                                                       $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', Array($fileInfo['file'], $theNewName));
-                                                                                       return $theRenameName;
-                                                                               } else {
-                                                                                       $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', Array($theTarget, $fileInfo['path']));
-                                                                               }
-                                                                       } else {
-                                                                               $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
-                                                                       }
-                                                               }
-                                                       } else {
-                                                               $this->writelog(5, 1, 120, 'Destination "%s" existed already!', Array($theRenameName));
-                                                       }
-                                               } else {
-                                                       $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', Array($fileInfo['path']));
-                                               }
-                                       } else {
-                                               $this->writelog(5, 1, 122, 'Old and new name is the same (%s)', Array($theNewName));
-                                       }
-                               } else {
-                                       $this->writelog(5, 2, 123, 'Target "%s" was neither a directory nor a file!', Array($theTarget));
-                               }
-                       } else {
-                               $this->writelog(5, 1, 124, 'New name "%s" was too long (max %s characters)', Array($theNewName, $this->maxInputNameLen));
+               $sourceFileObject = $this->getFileObject($cmds['data']);
+               $targetFile = $cmds['target'];
+               $resultObject = NULL;
+
+               if ($sourceFileObject instanceof t3lib_file_File) {
+                       try {
+                                       // Try to rename the File
+                               $resultObject = $sourceFileObject->rename($targetFile);
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
+                               $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
+                       } catch (t3lib_file_exception_IllegalFileExtensionException $e) {
+                               $this->writelog(5, 1, 101, 'Extension of file name "%s" was not allowed!', array($targetFile));
+                       } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                               $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
+                       } catch (t3lib_file_exception_NotInMountPointException $e) {
+                               $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
+                       } catch (RuntimeException $e) {
+                                       $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
+                       }
+                       $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
+
+               } else { // Else means this is a Folder
+                       try {
+                                       // Try to rename the Folder
+                               $resultObject = $sourceFileObject->rename($targetFile);
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
+                               $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
+                       } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                               $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
+                       } catch (t3lib_file_exception_NotInMountPointException $e) {
+                               $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
+                       } catch (RuntimeException $e) {
+                                       $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
                        }
+                       $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
                }
+
+               return $resultObject;
        }
 
        /**
         * This creates a new folder. (action=6)
         *
-        * @param       array           $cmds['data'] is the foldername. $cmds['target'] is the path where to create it.
-        * @return      string          Returns the new foldername upon success
+        * $cmds['data'] (string): The new folder name
+        * $cmds['target'] (string): The path where to copy to.
+        * + example "2:targetpath/targetfolder/"
+        *
+        * @param array $cmds Command details as described above
+        * @return t3lib_file_Folder Returns the new foldername upon success
         */
        function func_newfolder($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
 
-               $theFolder = $this->cleanFileName($cmds['data']);
-               if (isset($theFolder) && trim($theFolder) != '') {
-                       if ($this->checkFileNameLen($theFolder)) {
-                               $theTarget = $this->is_directory($cmds['target']); // Check the target dir
-                               if ($theTarget) {
-                                       if ($this->actionPerms['newFolder']) {
-                                               $theNewFolder = $theTarget . '/' . $theFolder;
-                                               if ($this->checkPathAgainstMounts($theNewFolder)) {
-                                                       if (!file_exists($theNewFolder)) {
-                                                               if (t3lib_div::mkdir($theNewFolder)) {
-                                                                       $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', Array($theFolder, $theTarget . '/'));
-                                                                       return $theNewFolder;
-                                                               } else {
-                                                                       $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', Array($theFolder, $theTarget . '/'));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', Array($theNewFolder));
-                                                       }
-                                               } else {
-                                                       $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', Array($theTarget . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
-                                       }
-                               } else {
-                                       $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', Array($cmds['target']));
-                               }
-                       } else {
-                               $this->writelog(6, 1, 105, 'New name "%s" was too long (max %s characters)', Array($theFolder, $this->maxInputNameLen));
-                       }
+               $targetFolderObject = $this->getFileObject($cmds['target']);
+
+               if (!($targetFolderObject instanceof t3lib_file_Folder)) {
+                       $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
+                       return FALSE;
+               }
+
+               $resultObject = NULL;
+
+               try {
+                       $folderName = $cmds['data'];
+                       $resultObject = $targetFolderObject->createFolder($folderName);
+                       $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
+               } catch (t3lib_file_exception_InsufficientFolderWritePermissionsException $e) {
+                       $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
+               } catch (t3lib_file_exception_NotInMountPointException $e) {
+                       $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
+               } catch (t3lib_file_exception_ExistingTargetFolderException $e) {
+                       $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
+               } catch (RuntimeException $e) {
+                       $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
                }
+
+               return $resultObject;
        }
 
        /**
         * This creates a new file. (action=8)
+        * $cmds['data'] (string): The new file name
+        * $cmds['target'] (string): The path where to create it.
+        * + example "2:targetpath/targetfolder/"
         *
-        * @param       array           $cmds['data'] is the new filename. $cmds['target'] is the path where to create it
-        * @return      string          Returns the new filename upon success
+        * @param array $cmds Command details as described above
+        * @return string Returns the new filename upon success
         */
        function func_newfile($cmds) {
-               $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
                if (!$this->isInit) {
                        return FALSE;
                }
-               $newName = $this->cleanFileName($cmds['data']);
-               if ($newName) {
-                       if ($this->checkFileNameLen($newName)) {
-                               $theTarget = $this->is_directory($cmds['target']); // Check the target dir
-                               $fileInfo = t3lib_div::split_fileref($theTarget); // Fetches info about path, name, extention of $theTarget
-                               if ($theTarget) {
-                                       if ($this->actionPerms['newFile']) {
-                                               $theNewFile = $theTarget . '/' . $newName;
-                                               if ($this->checkPathAgainstMounts($theNewFile)) {
-                                                       if (!file_exists($theNewFile)) {
-                                                               $fI = t3lib_div::split_fileref($theNewFile);
-                                                               if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
-                                                                       if (t3lib_div::inList($extList, $fI['fileext'])) {
-                                                                               if (t3lib_div::writeFile($theNewFile, '')) {
-                                                                                       clearstatcache();
-                                                                                       $this->writelog(8, 0, 1, 'File created: "%s"', Array($fI['file']));
-                                                                                       return $theNewFile;
-                                                                               } else {
-                                                                                       $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', Array($fI['file'], $theTarget));
-                                                                               }
-                                                                       } else {
-                                                                               $this->writelog(8, 1, 107, 'File extension "%s" is not a textfile format! (%s)', Array($fI['fileext'], $extList));
-                                                                       }
-                                                               } else {
-                                                                       $this->writelog(8, 1, 106, 'Extension of file name "%s" was not allowed!', Array($fI['file']));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(8, 1, 101, 'File "%s" existed already!', Array($theNewFile));
-                                                       }
-                                               } else {
-                                                       $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', Array($theTarget . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
-                                       }
-                               } else {
-                                       $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', Array($cmds['target']));
-                               }
-                       } else {
-                               $this->writelog(8, 1, 105, 'New name "%s" was too long (max %s characters)', Array($newName, $this->maxInputNameLen));
-                       }
+
+               $targetFolderObject = $this->getFileObject($cmds['target']);
+
+               if (!($targetFolderObject instanceof t3lib_file_Folder)) {
+                       $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
+                       return FALSE;
+               }
+
+               $resultObject = NULL;
+
+               try {
+                       $fileName = $cmds['data'];
+                       $resultObject = $targetFolderObject->createFile($fileName);
+                       $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
+               } catch (t3lib_file_exception_InsufficientFolderWritePermissionsException $e) {
+                       $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
+               } catch (t3lib_file_exception_NotInMountPointException $e) {
+                       $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
+               } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                       $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
+               } catch (t3lib_file_exception_InvalidFileNameException $e) {
+                       $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
+               } catch (RuntimeException $e) {
+                       $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
                }
+
+               return $resultObject;
        }
 
        /**
         * Editing textfiles or folders (action=9)
         *
-        * @param       array           $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
-        * @return      boolean         Returns true on success
+        * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
+        * @return boolean Returns TRUE on success
         */
        function func_edit($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
-               $theTarget = $cmds['target'];
+
+                       // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
+                       // for backwards compatibility: the combined file identifier was the path+filename
+               $fileIdentifier = $cmds['target'];
+               $fileObject = $this->getFileObject($fileIdentifier);
+
+                       // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
                $content = $cmds['data'];
+
+               if (!$fileObject instanceof t3lib_file_File) {
+                       $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
+                       return FALSE;
+               }
+
                $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
-               $type = filetype($theTarget);
-               if ($type == 'file') { // $type MUST BE file
-                       $fileInfo = t3lib_div::split_fileref($theTarget); // Fetches info about path, name, extention of $theTarget
-                       $fI = $fileInfo;
-                       if ($this->checkPathAgainstMounts($fileInfo['path'])) {
-                               if ($this->actionPerms['editFile']) {
-                                       $fI = t3lib_div::split_fileref($theTarget);
-                                       if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
-                                               if (t3lib_div::inList($extList, $fileInfo['fileext'])) {
-                                                       if (t3lib_div::writeFile($theTarget, $content)) {
-                                                               clearstatcache();
-                                                               $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', Array($fileInfo['file'], @filesize($theTarget), md5($content)));
-                                                               return TRUE;
-                                                       } else {
-                                                               $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem in "%s"?', Array($theTarget, $fileInfo['path']));
-                                                       }
-                                               } else {
-                                                       $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', Array($fI['fileext'], $extList));
-                                               }
-                                       } else {
-                                               $this->writelog(9, 1, 103, 'Extension of file name "%s" was not allowed!', Array($fI['file']));
-                                       }
-                               } else {
-                                       $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
-                               }
-                       } else {
-                               $this->writelog(9, 1, 121, 'Destination path "%s" was not within your mountpoints!', Array($fileInfo['path']));
-                       }
-               } else {
-                       $this->writelog(9, 2, 123, 'Target "%s" was not a file!', Array($theTarget));
+               if (!t3lib_div::inList($extList, $fileObject->getExtension())) {
+                       $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
+                       return FALSE;
+               }
+
+               try {
+                       $fileObject->setContents($content);
+                       clearstatcache();
+                       $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
+                       return TRUE;
+               } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
+                       $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
+                       return FALSE;
+               } catch (t3lib_file_exception_InsufficientFileWritePermissionsException $e) {
+                       $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
+                       return FALSE;
                }
        }
 
        /**
         * Upload of files (action=1)
+        * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
+        *      Array(
+        *              [upload_1] => Array(
+        *                              [name] => Array(
+        *                                              [0] => GData - Content-Elemente und Media-Gallery.pdf
+        *                                              [1] => CMS Expo 2011.txt
+        *                                      )
+        *                              [type] => Array(
+        *                                              [0] => application/pdf
+        *                                              [1] => text/plain
+        *                                      )
+        *                              [tmp_name] => Array(
+        *                                              [0] => /Applications/MAMP/tmp/php/phpNrOB43
+        *                                              [1] => /Applications/MAMP/tmp/php/phpD2HQAK
+        *                                      )
+        *                              [size] => Array(
+        *                                              [0] => 373079
+        *                                              [1] => 1291
+        *                                      )
+        *                      )
+        *      )
+        * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
         *
-        * @param       array           $cmds['data'] is the ID-number (points to the global var that holds the filename-ref  ($_FILES['upload_'.$id]['name']). $cmds['target'] is the target directory, $cmds['charset'] is the the character set of the file name (utf-8 is needed for JS-interaction)
-        * @return      string          Returns the new filename upon success
+        * @param array $cmds $cmds['data'] is the ID-number (points to the global var that holds the filename-ref  ($_FILES['upload_' . $id]['name']) . $cmds['target'] is the target directory, $cmds['charset'] is the the character set of the file name (utf-8 is needed for JS-interaction)
+        * @return string Returns the new filename upon success
         */
        function func_upload($cmds) {
                if (!$this->isInit) {
                        return FALSE;
                }
-               $id = $cmds['data'];
-               if ($_FILES['upload_' . $id]['name']) {
-                       $theFile = $_FILES['upload_' . $id]['tmp_name']; // filename of the uploaded file
-                       $theFileSize = $_FILES['upload_' . $id]['size']; // filesize of the uploaded file
-                       $theName = $this->cleanFileName(stripslashes($_FILES['upload_' . $id]['name']), (isset($cmds['charset']) ? $cmds['charset'] : '')); // The original filename
-                       if (is_uploaded_file($theFile) && $theName) { // Check the file
-                               if ($this->actionPerms['uploadFile']) {
-                                       if ($theFileSize < ($this->maxUploadFileSize * 1024)) {
-                                               $fI = t3lib_div::split_fileref($theName);
-                                               $theTarget = $this->is_directory($cmds['target']); // Check the target dir
-                                               if ($theTarget && $this->checkPathAgainstMounts($theTarget . '/')) {
-                                                       if ($this->checkIfAllowed($fI['fileext'], $theTarget, $fI['file'])) {
-                                                               $theNewFile = $this->getUniqueName($theName, $theTarget, $this->dontCheckForUnique);
-                                                               if ($theNewFile) {
-                                                                       t3lib_div::upload_copy_move($theFile, $theNewFile);
-                                                                       clearstatcache();
-                                                                       if (@is_file($theNewFile)) {
-                                                                               $this->internalUploadMap[$id] = $theNewFile;
-                                                                               $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', Array($theName, $theNewFile, $id));
-                                                                               return $theNewFile;
-                                                                       } else {
-                                                                               $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', Array($theTarget . '/'));
-                                                                       }
-                                                               } else {
-                                                                       $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', Array($theTarget . '/'));
-                                                               }
-                                                       } else {
-                                                               $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', Array($fI['file'], $theTarget . '/'));
-                                                       }
-                                               } else {
-                                                       $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', Array($theTarget . '/'));
-                                               }
-                                       } else {
-                                               $this->writelog(1, 1, 104, 'The uploaded file exceeds the size-limit of %s bytes', Array($this->maxUploadFileSize * 1024));
-                                       }
+
+               $uploadPosition = $cmds['data'];
+               $uploadedFileData = $_FILES['upload_' . $uploadPosition];
+
+               if (empty($uploadedFileData['name']) || (is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0]))) {
+                       $this->writelog(1, 2, 108, 'No file was uploaded!', '');
+                       return FALSE;
+               }
+
+                       // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
+               $targetFolderObject = $this->getFileObject($cmds['target']);
+
+                       // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
+               if (!is_array($uploadedFileData['name'])) {
+                       $uploadedFileData = array(
+                               'name' => array($uploadedFileData['name']),
+                               'type' => array($uploadedFileData['type']),
+                               'tmp_name' => array($uploadedFileData['tmp_name']),
+                               'size' => array($uploadedFileData['size']),
+                       );
+               }
+
+               $resultObjects = array();
+
+               $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
+                       // Loop through all uploaded files
+               for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++) {
+                       $fileInfo = array(
+                               'name'     => $uploadedFileData['name'][$i],
+                               'type'     => $uploadedFileData['type'][$i],
+                               'tmp_name' => $uploadedFileData['tmp_name'][$i],
+                               'size'     => $uploadedFileData['size'][$i],
+                       );
+                       try {
+
+                                       // @todo can be improved towards conflict mode naming
+                               if ($this->dontCheckForUnique) {
+                                       $conflictMode = 'replace';
                                } else {
-                                       $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
+                                       $conflictMode = 'cancel';
                                }
-                       } else {
+                               $resultObjects[] = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
+                               $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
+
+                       } catch (t3lib_file_exception_UploadException $e) {
                                $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
+                       } catch (t3lib_file_exception_InsufficientUserPermissionsException $e) {
+                               $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
+                       } catch (t3lib_file_exception_UploadSizeException $e) {
+                               $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
+                       } catch (t3lib_file_exception_InsufficientFolderWritePermissionsException $e) {
+                               $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_IllegalFileExtensionException $e) {
+                               $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
+                       } catch (t3lib_file_exception_ExistingTargetFileNameException $e) {
+                               $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
+                       } catch (RuntimeException $e) {
+                               $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
                        }
-               } else {
-                       $this->writelog(1, 2, 108, 'No file was uploaded!', '');
                }
+
+               return $resultObjects;
        }
 
        /**
         * Unzipping file (action=7)
         * This is permitted only if the user has fullAccess or if the file resides
         *
-        * @param       array           $cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
-        * @return      boolean         Returns true on success
+        * @param array $cmds $cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
+        * @return boolean Returns TRUE on success
         */
        function func_unzip($cmds) {
                if (!$this->isInit || $this->dont_use_exec_commands) {
@@ -982,45 +926,45 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
                }
 
                $theFile = $cmds['data'];
-               if (@is_file($theFile)) {
-                       $fI = t3lib_div::split_fileref($theFile);
-                       if (!isset($cmds['target'])) {
-                               $cmds['target'] = $fI['path'];
-                       }
-                       $theDest = $this->is_directory($cmds['target']); // Clean up destination directory
-                       if ($theDest) {
-                               if ($this->actionPerms['unzipFile']) {
-                                       if ($fI['fileext'] == 'zip') {
-                                               if ($this->checkIfFullAccess($theDest)) {
-                                                       if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
-                                                               // No way to do this under windows.
-                                                               $cmd = $this->unzipPath . 'unzip -qq "' . $theFile . '" -d "' . $theDest . '"';
-                                                               t3lib_utility_Command::exec($cmd);
-                                                               $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', Array($theFile, $theDest));
-                                                               return TRUE;
-                                                       } else {
-                                                               $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', Array($theFile, $theDest));
-                                                       }
-                                               } else {
-                                                       $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', Array($theDest));
-                                               }
-                                       } else {
-                                               $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
-                                       }
-                               } else {
-                                       $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
-                               }
-                       } else {
-                               $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', Array($cmds['target']));
-                       }
+               if (!@is_file($theFile)) {
+                       $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
+                       return FALSE;
+               }
+               $fI = t3lib_div::split_fileref($theFile);
+               if (!isset($cmds['target'])) {
+                       $cmds['target'] = $fI['path'];
+               }
+                       // Clean up destination directory
+                       // !!! Method has been put in the local driver, can be saftely removed
+               $theDest = $this->is_directory($cmds['target']);
+               if (!$theDest) {
+                       $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
+                       return FALSE;
+               }
+               if (!$this->actionPerms['unzipFile']) {
+                       $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
+                       return FALSE;
+               }
+               if ($fI['fileext'] != 'zip') {
+                       $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
+                       return FALSE;
+               }
+               if (!$this->checkIfFullAccess($theDest)) {
+                       $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
+                       return FALSE;
+               }
+                       // !!! Method has been put in the sotrage driver, can be saftely removed
+               if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
+                               // No way to do this under windows.
+                       $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
+                       t3lib_utility_Command::exec($cmd);
+                       $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
+                       return TRUE;
                } else {
-                       $this->writelog(7, 2, 105, 'The file "%s" did not exist!', Array($theFile));
+                       $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
+                       return FALSE;
                }
        }
 }
 
-if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php'])) {
-       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php']);
-}
-
 ?>
\ No newline at end of file