diff --git a/controllers/admin/AdminAttachmentsController.php b/controllers/admin/AdminAttachmentsController.php index 30ab36cd5..16c8d2f4c 100644 --- a/controllers/admin/AdminAttachmentsController.php +++ b/controllers/admin/AdminAttachmentsController.php @@ -151,12 +151,15 @@ class AdminAttachmentsControllerCore extends AdminController ); else { + do $uniqid = sha1(microtime()); while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid)); if (!copy($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid)) $this->errors[] = $this->l('Failed to copy the file.'); $_POST['file_name'] = $_FILES['file']['name']; @unlink($_FILES['file']['tmp_name']); + if (!sizeof($this->errors) && isset($a) && file_exists(_PS_DOWNLOAD_DIR_.$a->file)) + unlink(_PS_DOWNLOAD_DIR_.$a->file); $_POST['file'] = $uniqid; $_POST['mime'] = $_FILES['file']['type']; } @@ -172,11 +175,14 @@ class AdminAttachmentsControllerCore extends AdminController ''.$upload_mb.'' ); } - else if (!empty($_FILES['file']['tmp_name'])) + else $this->errors[] = $this->l('Upload error. Please check your server configurations for the maximum upload size allowed.'); } $this->validateRules(); } - return parent::postProcess(); + $return = parent::postProcess(); + if (!$return && isset($uniqid) && file_exists(_PS_DOWNLOAD_DIR_.$uniqid)) + @unlink(_PS_DOWNLOAD_DIR_.$uniqid); + return $return; } }