File Type Valdiation Not Work


I created form to upload files , also model to validate types .

If I upload php file or any file will upload in successful way ,

but in model i added files type

just "jpg,gif, png,pdf,rar,zip,doc,docx"

How to fix it ?

view :



	<div class="form">


	<?php $form=$this->beginWidget('CActiveForm', array(






        	'clientOptions'=>array('validateOnSubmit'=>true), //This is very important




        	'clientOptions'=>array('validateOnSubmit'=>true), //This is very important

   		'htmlOptions' => array('enctype' => 'multipart/form-data'),


	)); ?>




	/// difine Section model 

	$models=new Courses;





	<?php echo $form->errorSummary($model,'يرجى تعديل الأخطاء التالية'); ?>



	<h3> إضافة ملفات الدورات</h3>



    		<div class="row">

			<?php echo $form->labelEx($model,'title'); ?>

			<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>

			<?php echo $form->error($model,'title'); ?>








    		<div class="row">

			<?php echo $form->labelEx($model,'desc'); ?>

			<?php echo $form->textField($model,'desc',array('size'=>60,'maxlength'=>600)); ?>

			<?php echo $form->error($model,'desc'); ?>







    	<div class="row">

			<?php echo $form->labelEx($model,'file'); ?>

			<?php echo $form->fileField($model,'file'); ?>

        	الملفات المسموحة : jpg,gif, png,pdf,rar,zip,doc,docx

			<?php echo $form->error($model,'file'); ?>







	public function rules()


			// NOTE: you should only define rules for those attributes that

			// will receive user inputs.

			return array(

				array('title, desc,  privacy', 'required','message'=>'يرجى ملئ حقل {attribute}  '),

				array('privacy', 'numerical', 'integerOnly'=>true),

		     	array('title', 'length', 'max'=>255),

		  		array('desc', 'length', 'max'=>600),


         		array('file', 'file', 'types'=>'jpg,gif, png,pdf,rar,zip,doc,docx','allowEmpty'=>true, 'on'=>'update'),

				// The following rule is used by search().

				// Please remove those attributes that should not be searched.

				array('f_id, title, desc, file, privacy', 'safe', 'on'=>'search'),





Controller :

	public function actionCreate()


			$model=new Cfiles;


        	$models= new Courses;


			// Uncomment the following line if AJAX validation is needed












     		/////// upload image functions 


     		$rnd = rand(0,999984375);  // generate random number between 0-9999







            	$fileName = "samilox$rnd.{$ext}";  // random number + file name




         		////////// end 






                      	if(!empty($uploadedFile))  // check if uploaded file is set or not


             		$uploadedFile->saveAs(Yii::app()->basePath.'/../cfillaf/'.$fileName);  // upload image to server 

                  	$model->file = $fileName;








              	echo " Work ";











          	echo " error";









          	echo $this->renderPartial('_form',array('model'=>$model),true,true);//This will bring out the view along with its script.


                	else $this->render('create',array(






Thanks in advance

did you miss the rule for upload file on ‘insert’?

array('file', 'file', 'types'=>'jpg,gif, png,pdf,rar,zip,doc,docx','allowEmpty'=>false, 'on'=>'insert'),

it’s work Thanks my bro Root