[Solved] File Validation Not Working

I am trying to create following rule

            array('attachment', 'file', 'types'=>'jpg, gif, png, pdf, jpeg', 'maxSize'=>1024 * 1024 * 2, 'tooLarge'=>'File has to be smaller than 2MB','wrongType'=>'Only jpg, gif, png, pdf, and jpeg filees are allowed.' , 'on'=>'create'),

            array('attachment', 'unsafe', 'on'=>'update'),

where attachment is a non db attribute, declared in model.

and in the controller



                        $file=CUploadedFile::getInstance($model, 'attachment');





I can attach any file type with any size, validation is not working.

Please help me identify the issue.

Any thoughts on this issue?

Not really, but, do you get some error messages? Try to call explicitly to $model->validate() and log errors… I’m not sure if this validator is really working (I guess YES) but maybe you need to adjust PHP vars like MAX_UPLOAD_SIZE and so.

That’s interesting i will check after work.

Good luck.

Managed to solve myself. Just replaced ‘on’=>‘create’ with ‘on’=>‘insert’ in the rule. Thanks anyhow.

Really? Is this a bug or works as expected? I though ‘create’ was default scenario in this case.

Anyway, thanks mate.

I am having a problem with this file validator. I put the ‘on’=>‘insert’ already but still it accepts all types of files without showing any error. What do I do? I tried up loading my code but is saying my post is spam cause I am a new here.

Post your model rules.