baseName . '-' . uniqid(); $file_name_extension = $file_name . '.' . $file->extension; $dir_file = '../../producer/web/uploads/'; $path_file = $dir_file . $file_name_extension; $file->saveAs($path_file); // resize image list($width, $height, $type, $attr) = getimagesize($path_file); if ($width > 500) { $image = Yii::$app->image->load($path_file); // big if ($width > 1600) { $image->resize(1600)->save($dir_file . $file_name . '-big.' . $file->extension); } // medium if ($width > 1024) { $image->resize(1024)->save($dir_file . $file_name . '-medium.' . $file->extension); } // small if ($width > 500) { $image->resize(500)->save($dir_file . $file_name . '-small.' . $file->extension); } } $model->$champs = $file_name_extension; } else { $model->$champs = $filename_old; } $model->save(); } }