php - Failed to set unsafe attribute

Solution:
CFileValidator is by default unsafe, from the docs:
safe property (available since v1.1.12) public boolean $safe;
whether attributes listed with this validator should be considered safe for massive assignment. For this validator it defaults to false.
So set 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.'),
Answer
Solution:
You have to set attribute of
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.'),
Answer
Solution:
In Yii2
Possible causes you get this error due to the form 'enctype' is not set properly for file uploads.
Failed to set unsafe attribute 'id' in
Enable the form multipart/form-data
// Form
$form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: malformed utf-8 characters, possibly incorrectly encoded
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.