Uploadedfile Cannot Be Blank

hi! i am trying to implement image upload on my app. however, i always encounter this error "UploadedFile cannot be blank" whenever I update an entry with upload field on it.

Here is my Model:




<?php


/**

 * This is the model class for table "nmrl_employee".

 *

 * The followings are the available columns in table 'nmrl_employee':

 * @property string $role

 * @property string $firstName

 * @property string $middleName

 * @property string $lastName

 * @property string $permanentAddress

 * @property string $birthdate

 * @property string $gender

 * @property string $mobileNumber

 * @property string $emailAddress

 * @property string $tin

 * @property string $sssNumber

 * @property string $philhealthNumber

 * @property string $pagibigId

 * @property string $shift

 * @property string $rank

 * @property string $team

 * @property integer $userId

 * @property string $username

 * @property string $password

 * @property string $currentAddress

 * @property string $telephoneNumber

 */

class Employee extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Employee the static model class

	 */

	public $uploadedFile;

	

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'nmrl_employee';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

		

	public function rules()

	{

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

		// will receive user inputs.

		return array(

			array('uploadedFile', 'file', 'types'=>'jpg, gif, png',

					 'maxSize'=>2097152, // 2MB

                	),

			array('uploadedFile', 'file', 'allowEmpty'=>true, 'on' => 'update'),

			array('uploadedFile', 'file', 'allowEmpty'=>false, 'on' => 'insert'),

			array('userId, username, password', 'required'),

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

			array('role, firstName, middleName, lastName, emailAddress, username', 'length', 'max'=>64),

			array('permanentAddress, currentAddress', 'length', 'max'=>300),

			array('gender', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,

			array('mobileNumber, telephoneNumber', 'length', 'max'=>24),

			array('tin, sssNumber, philhealthNumber, pagibigId, shift, rank, team', 'length', 'max'=>32),

			array('password', 'length', 'max'=>100),

			array('birthdate', 'type', 'type'=>'date','message'=>'This is not a valid date!', 'dateFormat'=>'yyyy-MM-dd'),

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

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

			array('role, firstName, middleName, lastName, permanentAddress, birthdate, gender, mobileNumber, emailAddress, tin, sssNumber, philhealthNumber, pagibigId, shift, rank, team, userId, username, password, currentAddress, telephoneNumber', 'safe', 'on'=>'search'),


		);

	}

	

	/**

	 * Saves the name, size, type and data of the uploaded file

	 */

	public function beforeSave()

	{

		if($file=CUploadedFile::getInstance($this,'uploadedFile'))

		{

			$this->file_name=$file->name;

			$this->file_type=$file->type;

			$this->file_size=$file->size;

			$this->file_content=file_get_contents($file->tempName);

		}

	

		return parent::beforeSave();

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'file_name' => 'File Name',

			'file_type' => 'File Type',

			'file_size' => 'File Size',

			'role' => 'Role',

			'firstName' => 'First Name',

			'middleName' => 'Middle Name',

			'lastName' => 'Last Name',

			'permanentAddress' => 'Permanent Address',

			'birthdate' => 'Birthdate',

			'gender' => 'Gender',

			'mobileNumber' => 'Mobile Number',

			'emailAddress' => 'Email Address',

			'tin' => 'TIN',

			'sssNumber' => 'SSS Number',

			'philhealthNumber' => 'Philhealth Number',

			'pagibigId' => 'Pag-ibig MID',

			'shift' => 'Shift',

			'rank' => 'Rank',

			'team' => 'Team',

			'userId' => 'User',

			'username' => 'Username',

			'password' => 'Password',

			'currentAddress' => 'Current Address',

			'telephoneNumber' => 'Telephone Number',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('role',$this->role,true);

		$criteria->compare('firstName',$this->firstName,true);

		$criteria->compare('middleName',$this->middleName,true);

		$criteria->compare('lastName',$this->lastName,true);

		$criteria->compare('permanentAddress',$this->permanentAddress,true);

		$criteria->compare('birthdate',$this->birthdate,true);

		$criteria->compare('gender',$this->gender,true);

		$criteria->compare('mobileNumber',$this->mobileNumber,true);

		$criteria->compare('emailAddress',$this->emailAddress,true);

		$criteria->compare('tin',$this->tin,true);

		$criteria->compare('sssNumber',$this->sssNumber,true);

		$criteria->compare('philhealthNumber',$this->philhealthNumber,true);

		$criteria->compare('pagibigId',$this->pagibigId,true);

		$criteria->compare('shift',$this->shift,true);

		$criteria->compare('rank',$this->rank,true);

		$criteria->compare('team',$this->team,true);

		$criteria->compare('userId',$this->userId);

		$criteria->compare('username',$this->username,true);

		$criteria->compare('password',$this->password,true);

		$criteria->compare('currentAddress',$this->currentAddress,true);

		$criteria->compare('telephoneNumber',$this->telephoneNumber,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

}



Here is my Controller (create and update part)




public function actionCreate()

	{

		$model=new Employee;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);

		

		

		if(isset($_POST['Employee']))

		{

			$model->attributes=$_POST['Employee'];

				

			if($model->save())

				$this->redirect(array('view','id'=>$model->userId));

		}


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

			'model'=>$model

		));

	}

	

	public function actionUpdate($id)

	{

		$model=$this->loadModel($id);

		$user = Users::model()->findByPk($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Employee']))

		{

			$model->attributes=$_POST['Employee'];

			if($model->save()){

				if ($model->file_name != NULL){

					$model->file_name=$model->file_name;

					$model->file_type=$model->file_type;

					$model->file_size=$model->file_size;

					$model->file_content=$model->file_content;

				}

				

				//CREATE LOG ENTRY

					

				$user= Employee::model()->findByAttributes(array('username'=>Yii::app()->user->name));

				

				$log = new Log();

				$log->userId = $user->userId;

				$log->action = 'updated';

				$log->category = 'profile';

				$log->categoryId = $model->employeeId;

				$log->date = date('Y/m/d h:i:s A');

				$log->save(false);

				

				$this->redirect(array('view','id'=>$model->userId));

		

			}

		}

		$this->render('update',array(

			'model'=>$model,

		));

	}



Here is my View…




<div class="row">

					<div class="photo">

			        <?php

			        echo '<img src="data:image/png;base64,' . base64_encode($model->file_content) . '"/>';?>

		 			</div>

		 		</div>

		

		 		<div class="row">

					<table class="uploadArea">

						<tr class="upload-row">

			            	<td><?php echo $form->labelEx($model,'uploadedFile'); ?></td>

			    	 	</tr>

			    	 	<tr class="upload-row">

			    	 		<td><?php echo CHtml::activeFileField($model,'uploadedFile'); ?></td>	

			    	 	</tr>

						<tr class="upload-row">

							<td><p class="note">Fields with <span class="required">*</span> are required.</p></td>

						</tr>

						<tr class="upload-row">

							<td><?php echo $form->errorSummary($model); ?></td>

						</tr>

					</table>

				</div>



try this, remove or comment(//) array(‘uploadedFile’, ‘file’, ‘allowEmpty’=>true, ‘on’ => ‘update’),