Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

File Validation Not Working

$
0
0
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

			$model->setAttributes($_POST['AgentAttachments']);
                        $model->agent_id=$this->_agent->agent_id;
                        $file=CUploadedFile::getInstance($model, 'attachment');
                        $model->attachment=$file;
                        $model->file_name=$model->attachment->name;
                        $model->extension=$model->attachment->extensionName;
                        $model->save();


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

Please help me identify the issue.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>