Cfileuploader And Validator

Hello,

can anyone tell me, why my code doesn’t work correctly:

Controller:




$myfile = CUploadedFile::getInstance($model,'image');

				echo $myfile;

				if (!empty($myfile->name) && strcmp($myfile->name, $model->image)!=0) {

					$myfile->saveAs(Yii::app() -> basePath . '/../images/challenges/'.$model -> id . '.jpg');

					$model->image = $model->id.'.jpg';

				} elseif (empty($model->image)) {

					$model->image = 'empty-challenge.jpg';

				}


				$myfile = CUploadedFile::getInstance($model,'big_image');

				echo $myfile;

				if (!empty($myfile->name) && strcmp($myfile->name, $model->big_image)!=0) {

					$myfile->saveAs(Yii::app() -> basePath . '/../images/challenges/'.$model -> id . '-image.jpg');

					$model->big_image = $model->id.'-image.jpg';

				} elseif (empty($model->image)) {

					$model->big_image = 'empty-challenge-image.jpg';

				}



View:




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

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



I always get error when i upload 2 files at the same time. It takes the Validation rule of the first Image and applyes it to the second?

whats the error u get ?

please paster ur error and rules ()

Thanks guys for replies, i have managed it :)

Here is the code:




$image = array();

$image[] = EUploadedImage::getInstance($model,'image');

$image[] = EUploadedImage::getInstance($model,'big_image');

	foreach($image as $key=>$image){

		if(!empty($image)){

			if($key==0) {

				$name = "image";

		                $suffix = "";

			        $size = 1000*1000;

						$image->maxWidth = 250;

						$image->maxHeight = 200;

					}

					else {

						$name = "big_image";

						$suffix = "-image";

						$size = 1000*1000;

						$image->maxWidth = 1000;

						$image->maxHeight = 240;

					}

						

					if($image->size > $size) {

						$model->addError($name,'Max image size is 1MB!');

					} else {

						//echo "$name: $image->width x $image->height $image->size KB";

						$image->saveAs(Yii::app() -> basePath . '/../images/challenges/'.$model -> id . $suffix . '.jpg');

						$model->$name = $model->id.$suffix.'.jpg';

					}

				}

			}