Hello, I’m trying to upload two photos from a form.
In my model the two photos are defined as following:
public $bild1;
public $bild2;
public function rules()
{
$ruleset = parent::rules();
$ruleset[] = array('bild1, bild2', 'file', 'maxSize' => 200*200*50,
'allowEmpty' => true,);
$ruleset[] = array('bild1, bild2', 'safe');
$ruleset[] = array(
'bild1, bild2', 'EImageValidator', 'allowEmpty' => true,
'types' => "jpg, png", 'typesError' => 'Falscher Dateityp',
'width' => 200, 'height' => 200, 'dimensionError' => 'Bild ist nicht 200x200 Pixel groß',
);
return $ruleset;
}
In the form I have the following code for the images (the form has the enctype multipart/form-data):
echo $form->fileField($model, 'bild1', array('id' => 'bild1Field'));
echo $form->error($model,'bild1');
echo $form->fileField($model, 'bild2', array('id' => 'bild2Field'));
echo $form->error($model,'bild2');
The part of the controller looks like this:
$model = new Musiker;
if (isset($_POST['Musiker'])) {
$model->setAttributes($_POST['Musiker']);
...
Every time I try to submit the form, I get the following error
Ungesichertes Attribut "bild1" konnte nicht gesetzt werden.
which means ‘Failed to set unsafe attribute’.
Any suggestions?