diff --git a/core/model/modx/sources/modfilemediasource.class.php b/core/model/modx/sources/modfilemediasource.class.php index 5b9ac30d3c2..15dee64f981 100644 --- a/core/model/modx/sources/modfilemediasource.class.php +++ b/core/model/modx/sources/modfilemediasource.class.php @@ -592,6 +592,25 @@ public function checkFiletype($filename) { return true; } + /** + * Check that an object (directory, file) exists + * + * @param string $objectPath The object path to check + * @param string $objectName The object name displayed in the error message + * @return bool + */ + protected function checkObjectExist($objectPath, $objectName) { + if (file_exists($objectPath)) { + if (is_dir($objectPath)) { + $this->addError('name', $this->xpdo->lexicon('file_folder_err_ae')); + return true; + } + $this->addError('name', sprintf($this->xpdo->lexicon('file_err_ae'), $objectName)); + return true; + } + return false; + } + /** * @param string $oldPath * @param string $newName @@ -622,13 +641,7 @@ public function renameObject($oldPath,$newName) { $newPath = $this->fileHandler->sanitizePath($newName); $newPath = dirname($oldPath).'/'.$newPath; - /* check to see if the new resource already exists */ - if (file_exists($newPath)) { - if (is_dir($newPath)) { - $this->addError('name',$this->xpdo->lexicon('file_folder_err_ae')); - return false; - } - $this->addError('name',sprintf($this->xpdo->lexicon('file_err_ae'),$newName)); + if ($this->checkObjectExist($newPath,$newName)) { return false; } @@ -875,6 +888,10 @@ public function uploadObjectsToContainer($container,array $objects = array()) { $newPath = $this->fileHandler->sanitizePath($file['name']); $newPath = $directory->getPath().$newPath; + if ($this->checkObjectExist($newPath,$file['name'])) { + return false; + } + if (!move_uploaded_file($file['tmp_name'],$newPath)) { $this->addError('path',$this->xpdo->lexicon('file_err_upload')); continue;