Failed to set unsafe attribute

Hi, I have a warning line in the log when inserting and updating.

2013/02/05 16:43:57 [warning] [application] Failed to set unsafe attribute "logo" of "Model". 

Rules for the model

 public function rules() { return array( array('typeId, cityId, new', 'numerical', 'integerOnly'=>true), array('title, url', 'length', 'max'=>255), array('content, created, deleted', 'safe'), array('url', 'url', 'on'=>'insert, update'), array('typeId, cityId, title', 'required', 'on'=>'insert, update'), array('logo', 'file', 'types'=>'jpg, jpeg, gif, png', 'maxSize'=>100*1024, 'allowEmpty'=>true, 'tooLarge'=>'{attribute} is too large to be uploaded. Maximum size is 100kB.'), array('id, typeId, cityId, title, content, new, url, logo', 'safe', 'on'=>'search'), ); } 

I don’t understand why I understand it. I have a rule for the logo field and allow it for it

+6
source share
3 answers

CFileValidator is not safe by default, from docs :

safe property (available since v1.1.12) public boolean $ safe;

Should the attributes listed in this validator be considered safe for mass use? The default value for this validator is false.

So set the safe attribute to true

 array('logo', 'file', 'types'=>'jpg, jpeg, gif, png','safe'=>true, 'maxSize'=>100*1024, 'allowEmpty'=>true, 'tooLarge'=>'{attribute} is too large to be uploaded. Maximum size is 100kB.'), 
+16
source

You must set the safe attribute CFileValidator to true

 array('logo', 'file', 'types'=>'jpg, jpeg, gif, png','safe'=>true, 'maxSize'=>100*1024, 'allowEmpty'=>true, 'tooLarge'=>'{attribute} is too large to be uploaded. Maximum size is 100kB.'), 
+3
source

In Yii2

Possible reasons for getting this error due to the 'enctype' form are not set correctly for file uploads.

 Failed to set unsafe attribute 'id' in 

Include form multipart / form-data p>

 // Form $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]); 
0
source

All Articles