From f38e984b3163950be2a4e53f3f3dd4e74dc16cd9 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 19 Aug 2015 07:07:31 +0100 Subject: [PATCH] Rename now working for FTP --- lib/file-control-xhr.php | 43 +++++++++++++++++++++++++++++----------- lib/ftp-control.php | 6 ++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/file-control-xhr.php b/lib/file-control-xhr.php index 9a3da4d..73242c1 100644 --- a/lib/file-control-xhr.php +++ b/lib/file-control-xhr.php @@ -406,20 +406,39 @@ if (!isset($ftpSite) && !$error && $_GET['action']=="move") { // RENAME FILE/FOLDER // ================== -if (!isset($ftpSite) && !$error && $_GET['action']=="rename") { - $renamed=false; - if (!$demoMode && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) { - if(rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName)) { - // Reload file manager - $doNext = 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'rename\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean($_GET['oldFileName'])).'\');'; - $finalAction = "rename"; - $renamed=true; - // Run our custom processes - include_once("../processes/on-file-dir-rename.php"); +if (!$error && $_GET['action']=="rename") { + if (!$demoMode && ($ftpSite || is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName']))))) { + $updateFM = false; + // FTP + if (isset($ftpSite)) { + ftpStart(); + // Show user warning if no good connection + if (!$ftpConn || !$ftpLogin) { + $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; + } else { + $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); + if (!ftpRename($ftpConn, ltrim(strClean($_GET['oldFileName']),"/"), $ftpFilepath)) { + $doNext = 'top.ICEcoder.message("Sorry, could not rename '.ltrim(strClean($_GET['oldFileName']),"/").' to '.$ftpFilepath.'");'; + } else { + $updateFM = true; + } + } + ftpEnd(); + // Local + } else { + rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName); + $updateFM = true; } - } - if (!$renamed) { + // Update file manager on success + if ($updateFM) { + $doNext = 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'rename\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean($_GET['oldFileName'])).'\');'; + } + $finalAction = "rename"; + // Run our custom processes + include_once("../processes/on-file-dir-rename.php"); + } else { $doNext = "top.ICEcoder.message('".$t['Sorry, cannot rename']."\\\\n".strClean($_GET['oldFileName'])."\\\\n\\\\n".$t['Maybe public write...']."');"; + $finalAction = "nothing"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; }; diff --git a/lib/ftp-control.php b/lib/ftp-control.php index 75ea868..0c9e195 100644 --- a/lib/ftp-control.php +++ b/lib/ftp-control.php @@ -77,6 +77,12 @@ function ftpMkDir($ftpConn, $perms, $dir) { } } +// Rename a dir/dile over FTP +function ftpRename($ftpConn, $oldPath, $newPath) { + // Return success status of rename + return ftp_rename($ftpConn, $oldPath, $newPath); +} + // Change dir/file perms over FTP function ftpPerms($ftpConn, $perms, $filePath) { // Return success status of perms change