Image Upload And Validaiton

Hello,

i have a model User where in rules() i have:


array('image', 'length', 'max'=>150),

array('image','file', 'allowEmpty'=>true, 'types'=>'jpg, gif, png, jpeg', 'maxSize'=>1024 * 1024, 'tooLarge'=>'File has to be smaller than 1MB'),

Part of the update action looks like this:


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

		{

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

			$model->image = EUploadedImage::getInstance($model,'image');

			$model->birthDate = Helper::createDbDate($model->birthDate);


			$this->performAjaxValidation($model);

My User form starts with:


<?php 

$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(

		'id'=>'user-form',

		'type'=>'horizontal',

		'enableAjaxValidation'=>true,

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

));

?>


<fieldset>

	<div class="row-fluid">

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


		<div class="form-4column">


			<h3>Avatar</h3>


			<div>

				<div class="user-image">

					<?php if($model->isNewRecord!='1'){

						if (strlen($model->image) != 0)

							?>

					<a class="thumbnail"> <img

						src="<?php echo Yii::app() -> request -> baseUrl . '/images/users/' . $model -> id . ".jpg"; ?>" />

					</a>

					<?php }

					else {

						?>

					<a class="thumbnail"> <img

						src="<?php echo Yii::app() -> request -> baseUrl . '/images/users/empty-user.jpg'; ?>" />

					</a>

					<?php

					}

					?>

				</div>

				<div class="user-image-select">

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

				</div>

			</div>

		</div>

So actually if i am uploading any file bigger than 1 MB and other type of jpg,gif,png and jpeg i should get an error in view, but i am not getting it?

Ah no, sorry it works, but only after the file is uploaded to the server. I would like to check the file before the user uploads a file to server. Is it possible?