diff --git a/php/elFinderVolumeDriver.class.php b/php/elFinderVolumeDriver.class.php index 3f9e3cc2d..f56da3927 100644 --- a/php/elFinderVolumeDriver.class.php +++ b/php/elFinderVolumeDriver.class.php @@ -3651,7 +3651,13 @@ abstract class elFinderVolumeDriver { * @author Dmitry (dio) Levashov */ public function uniqueName($dir, $name, $suffix = ' copy', $checkNum = true, $start = 1) { - $ext = ''; + static $lasts = null; + + if ($lasts === null) { + $lasts = array(); + } + + $ext = ''; if (preg_match('/\.((tar\.(gz|bz|bz2|z|lzo))|cpio\.gz|ps\.gz|xcf\.(gz|bz2)|[a-z0-9]{1,4})$/i', $name, $m)) { $ext = '.'.$m[1]; @@ -3666,12 +3672,17 @@ abstract class elFinderVolumeDriver { $name .= $suffix; } $max = $i+100000; + + if (isset($lasts[$name])) { + $i = max($i, $lasts[$name]); + } while ($i <= $max) { $n = $name.($i > 0 ? sprintf($this->options['uniqueNumFormat'], $i) : '').$ext; if (!$this->isNameExists($this->joinPathCE($dir, $n))) { $this->clearcache(); + $lasts[$name] = ++$i; return $n; } $i++; diff --git a/php/elFinderVolumeLocalFileSystem.class.php b/php/elFinderVolumeLocalFileSystem.class.php index 717d9fbf4..7309e3c1c 100644 --- a/php/elFinderVolumeLocalFileSystem.class.php +++ b/php/elFinderVolumeLocalFileSystem.class.php @@ -1122,6 +1122,21 @@ class elFinderVolumeLocalFileSystem extends elFinderVolumeDriver { return $this->rmdirRecursive($localpath); } + /** + * Return fileinfo based on filename + * For item ID based path file system + * Please override if needed on each drivers + * + * @param string $path file cache + * @return array + */ + protected function isNameExists($path) { + $res = file_exists($this->convEncIn($path)); + // restore locale + $this->convEncOut(); + return $res; + } + /******************** Over write (Optimized) functions *************************/ /**