FIleValidator not giving expected result

Hi,

I have a File model extending Active Record for my files - some info below




public $single_image;

...

public function rules() {

   ...

   [['single_image'], 'file','extensions' => 'png', 'mimeTypes' => 'image/png'],

}



and in my controller for the create action (the $model here refers to a page model)




$model = new Page();

$fileModel = new File();

if ($model->load(Yii::$app->request->post())) {

   $image = UploadedFile::getInstance($fileModel, 'single_image');

   if ($image && $fileModel->validate()) {

      ...save...

      ... do redirection etc

   }


}



In my view have




<?= $form->field($fileModel,'single_image')->fileInput();?>



What’s not happening is that if I upload for example a jpeg, I am not getting an error message - when the rule above states that I can only upload png …

Can you help me with this?

Also, any help on using the image validator would be great too!

You validate $fileModel but it doesn’t contains the image posted




$model = new Page();

$fileModel = new File();

if ($model->load(Yii::$app->request->post())) {

   //Modification here

   $fileModel->single_image = UploadedFile::getInstance($fileModel, 'single_image');

   if ($fileModel->validate()) {

      ...save...

      ... do redirection etc

   }


}



It should works ;)

http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html#controller

Many thanks - much appreciated!