From 2ee777739f64348c7865bffe21a4ae851b4e8c07 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 13 Jan 2013 15:13:34 +0000 Subject: [PATCH] Paste same name files with postfixed next nos $dest now has double slashes replaced with singles Now also considers if a file exists before copying If it does, next available number up to 1 billion postfixed to end of filename Copy with that new filename, next number postfixed Slight adjust to filename shown in file manager to match --- lib/file-control.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/file-control.php b/lib/file-control.php index bec474d..945ef96 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -55,7 +55,7 @@ if ($_GET['action']=="newFolder") { // If we're due to paste a new file... if ($_GET['action']=="paste") { $source = $file; - $dest = $docRoot.strClean(str_replace("|","/",$_GET['location']))."/".basename($source); + $dest = str_replace("//","/",$docRoot.strClean(str_replace("|","/",$_GET['location']))."/".basename($source)); if (!$demoMode && is_writable(dirname($dest))) { if (is_dir($source)) { if (!is_dir($dest)) { @@ -72,10 +72,20 @@ if ($_GET['action']=="paste") { } } } else { - copy($source, $dest); + if (!file_exists($dest)) { + copy($source, $dest); + } else { + for ($i=2; $i<1000000000; $i++) { + if (!file_exists($dest." (".$i.")")) { + $dest = $dest." (".$i.")"; + copy($source, $dest); + $i=1000000000; + } + } + } } // Reload file manager - echo ''; + echo ''; } else { echo ""; }