sjaakp / yii2-illustrated-behavior

Adds image to ActiveRecord
http://www.sjaakpriester.nl/software/illustrated
MIT License
43 stars 17 forks source link

fileValidation does not work. can upload any type file resulting in errors #21

Open MamlukiSn opened 8 years ago

MamlukiSn commented 8 years ago

Not sure if i'm doing something wrong but the extension does not validate for images. It allows all other extensions resulting in errors below Imagine\Exception\RuntimeException

Unable to open image /tmp/php7Bv8a7 ↵ Caused by: Imagine\Exception\InvalidArgumentException

An image could not be created from the given input

Could i be doing this wrong. I tried it again with a new active record model with and without fileValidation and both allow all types of extensions (sql files archives etc )

<--model--> public function behaviors() { $behaviors = parent::behaviors(); $behaviors[] = [ "class" => Illustrated::className(), 'attributes' => [ 'avatar' => [ 'aspectRatio' => 1, 'cropSize' => 200, 'tooSmallMsg'=> 'The Image uploaded "%s" is too small (%d×%d) to crop or scale to an appropriate picture.' ],
], 'directory' => '@images', 'baseUrl' => '@imagesurl', 'noImage'=>'Not a valid image', 'fileValidation'=>[ 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024, ],

    ];

    return $behaviors;
}

<--View-->

<?= $form->field($model, 'avatar')->widget(Uploader::className(), [ 'stylefileOptions' => [ 'btnClass' => 'btn btn-default', 'btnText' => 'Please, browse for image' ], 'cropperOptions' => [ 'diagonal' => 240, 'margin' => 5, 'sliderPosition' => 'right', 'sliderOptions' => [ 'animate' => 'slow' ] ], 'deleteOptions' => [ 'label' => '', // Font Awesome icon 'title' => 'Delete image' ], ],

                )->label(false) ?>
mishamx commented 8 years ago

+1

dfuse-dev commented 7 years ago

Same here. Could you share your model rules? I cant manage to get validation errors for size, extensions, etc.

Thanks