yii-dream-team / yii2-upload-behavior

Yii2 file/image upload behavior for ActiveRecord
http://yiidreamteam.com/yii2/upload-behavior
MIT License
77 stars 45 forks source link

bug GD in php 8.1 sizeof(): Argument #1 ($value) must be of type Countable|array, null given #38

Open lllyx1 opened 8 months ago

lllyx1 commented 8 months ago

sizeof(): Argument #1 ($value) must be of type Countable|array, null given

code

<?php

namespace app\models;

use Yii;
use yiidreamteam\upload\ImageUploadBehavior;

/**
 * This is the model class for table "reviews".
 *
 * @property int $id
 * @property string|null $name
 * @property string|null $body
 * @property string|null $avatar
 * @property int|null $rating
 *
 * @mixin ImageUploadBehavior
 */
class Reviews extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'reviews';
    }
    public function behaviors(): array
    {
        return [
            [
                'class' => ImageUploadBehavior::class,
                'attribute' => 'avatar',
                'createThumbsOnRequest' => true,
                'filePath' => '@webroot/origin/reviews/[[id]].[[extension]]',
                'fileUrl' => '@web/origin/reviews/[[id]].[[extension]]',
                'thumbPath' => '@webroot/cache/reviews/[[profile]]_[[id]].[[extension]]',
                'thumbUrl' => '@web/cache/reviews/[[profile]]_[[id]].[[extension]]',
                'thumbs' => [
                    'thumb' => ['width'=>286, 'height'=>220],
                    'mini' => ['width' => 240, 'height' => 160],
                    'admin' => ['width'=> 100, 'height'=>100],
                    'webp_thumb' => ['width' => 100, 'height' => 100, 'extension' => 'webp'],
                ],
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'body'], 'string'],
            [['rating'], 'integer'],
            ['avatar', 'image', 'extensions' => 'jpg, jpeg, gif, png']
        ];
    }

}

Corrected if written in the GD file protected $options = [];