[-] BO : Fix bug #PSCFV-10718 AdminAttachments old file not deleted on update

This commit is contained in:
gRoussac committed 2013-10-24 22:42:13 +02:00
1 parent 4cd3e1b830
commit 438a3dda2b
1 file changed
+8 -2
@@ -151,12 +151,15 @@ class AdminAttachmentsControllerCore extends AdminController
); );
else else
{ {
do $uniqid = sha1(microtime()); do $uniqid = sha1(microtime());
while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid)); while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid));
if (!copy($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid)) if (!copy($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid))
$this->errors[] = $this->l('Failed to copy the file.'); $this->errors[] = $this->l('Failed to copy the file.');
$_POST['file_name'] = $_FILES['file']['name']; $_POST['file_name'] = $_FILES['file']['name'];
@unlink($_FILES['file']['tmp_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['file'] = $uniqid;
$_POST['mime'] = $_FILES['file']['type']; $_POST['mime'] = $_FILES['file']['type'];
} }
@@ -172,11 +175,14 @@ class AdminAttachmentsControllerCore extends AdminController
'<b>'.$upload_mb.'</b>' '<b>'.$upload_mb.'</b>'
); );
} }
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->errors[] = $this->l('Upload error. Please check your server configurations for the maximum upload size allowed.');
} }
$this->validateRules(); $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;
} }
} }