From: Vladimir Fomichev Date: Thu, 4 Sep 2025 09:49:10 +0000 (+0300) Subject: Добавил Параметр удаления временных файлов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=85cde75db0c5c9019c9ed7e835889270eef7ec39;p=erp24_rep%2Fyii-erp24%2F.git Добавил Параметр удаления временных файлов --- diff --git a/erp24/controllers/MatrixErpController.php b/erp24/controllers/MatrixErpController.php index 26fa85be..aec0f927 100644 --- a/erp24/controllers/MatrixErpController.php +++ b/erp24/controllers/MatrixErpController.php @@ -427,7 +427,7 @@ class MatrixErpController extends Controller if ($uploadImage) { if (Images::isImageFile($uploadImage, ['png', 'jpg', 'jpeg', 'webp', 'gif'])) { $image = new Images(); - $imageId = $image->loadImage($uploadImage); + $imageId = $image->loadImage($uploadImage, false); if (!empty($imageId)) { $matrixProductProperty->image_id = $imageId; diff --git a/erp24/records/Images.php b/erp24/records/Images.php index 01460daa..b2500e63 100644 --- a/erp24/records/Images.php +++ b/erp24/records/Images.php @@ -72,7 +72,7 @@ class Images extends \yii\db\ActiveRecord * @param UploadedFile $file_obj * @return bool|int|null */ - public function loadImage(UploadedFile $file_obj = null) + public function loadImage(UploadedFile $file_obj = null, $deleteTempFile = true) { if (!$file_obj) { return null; @@ -94,7 +94,7 @@ class Images extends \yii\db\ActiveRecord mkdir($imageDirPath); } - if ($file_obj->saveAs($imageDirPath . '/' . $file_name, false)) { + if ($file_obj->saveAs($imageDirPath . '/' . $file_name, $deleteTempFile)) { $this->original_name = $file_obj->baseName; $this->filename = $file_name; $this->size = $file_obj->size; @@ -106,6 +106,7 @@ class Images extends \yii\db\ActiveRecord $validate = $this->validate(); if ($validate) { $this->save(); + if (preg_match('/^\.jpe?g$/i', $ext)) { exec('jpegoptim --all-progressive -v --strip-all ' . Yii::getAlias('uploads/images/' . $dir_name . '/' . $file_name)); } elseif (preg_match('/^\.png$/i', $ext)) {