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;
* @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;
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;
$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)) {