From c11347cf6e47745679ccc03a08e5c2906c539ca5 Mon Sep 17 00:00:00 2001 From: Teddy Date: Tue, 30 Sep 2025 09:51:04 +0200 Subject: [PATCH] Fix bug "Path cannot be empty" after saving module's configuration --- everpsquotation.php | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/everpsquotation.php b/everpsquotation.php index 9b996a8..70071b5 100644 --- a/everpsquotation.php +++ b/everpsquotation.php @@ -728,43 +728,45 @@ protected function postProcess() ); /* Uploads image */ - $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image']['name'], '.'), 1)); - $imagesize = @getimagesize($_FILES['image']['tmp_name']); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && - !empty($_FILES['image']['tmp_name']) && - !empty($imagesize) && - in_array( - Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), - [ - 'jpg', - 'gif', - 'jpeg', - 'png', - ] - ) && - in_array($type, ['jpg', 'gif', 'jpeg', 'png']) + !empty($_FILES['image']['tmp_name']) ) { - $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); - - if ($error = ImageManager::validateUpload($_FILES['image'])) { - $this->postErrors[] = $error; - } elseif (!$temp_name - || !move_uploaded_file($_FILES['image']['tmp_name'], $temp_name) + $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image']['name'], '.'), 1)); + $imagesize = @getimagesize($_FILES['image']['tmp_name']); + if (!empty($imagesize) && + in_array( + Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), + [ + 'jpg', + 'gif', + 'jpeg', + 'png', + ] + ) && + in_array($type, ['jpg', 'gif', 'jpeg', 'png']) ) { - $this->postErrors[] = $this->l('An error occurred during the image upload process.'); - } elseif (!ImageManager::resize( - $temp_name, - dirname(__FILE__).'/views/img/quotation.jpg', - null, - null, - $type - )) { - $this->postErrors[] = $this->l('An error occurred during the image upload process.'); - } + $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); - if (isset($temp_name)) { - @unlink($temp_name); + if ($error = ImageManager::validateUpload($_FILES['image'])) { + $this->postErrors[] = $error; + } elseif (!$temp_name + || !move_uploaded_file($_FILES['image']['tmp_name'], $temp_name) + ) { + $this->postErrors[] = $this->l('An error occurred during the image upload process.'); + } elseif (!ImageManager::resize( + $temp_name, + dirname(__FILE__).'/views/img/quotation.jpg', + null, + null, + $type + )) { + $this->postErrors[] = $this->l('An error occurred during the image upload process.'); + } + + if (isset($temp_name)) { + @unlink($temp_name); + } } } $this->postSuccess[] = $this->l('All settings have been saved :-)');