Having types in filefield

I have made my file field to have certain options like jpg, png using the below code.

$form->fileField($model,'photo',array('types'=>'jpg, gif, png'))

Is it right.

I have seen the documentation filefield

but am not sure if placing it like this is correct

,array('types'=>'jpg, gif, png')

Any Help

You can do the file validation in the model, Here is the link that might help.


In your model rules define like below

array('photo', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true),