$Model->Save In Foreach() Saves Record Only Once

This is my code for CMultiFileUpload. Everything working fine except file saving in table only once. is there any saveAll() or something???




public function actionMultiplePhoto($id)

	{

		$model = new PropertyPhoto;

		 

		$file = CUploadedFile::getInstancesByName('location');

        var_dump($file);

		if(!empty($file))

		{

			foreach($file as $thefile)

			{   

				echo $thefile->name;

				$rnd = rand(0,9999);

				$fileName = "{$rnd}-{$thefile}";

				$model->location = $fileName;

				$model->property_id = $id;

				$model->status = 'waiting';

				$model->save();

				$thefile->saveAs(getcwd().'/picture/upload/'.$model->location);

				               

			}

		}

		$this->render('multiplePhoto',array('model'=>$model));

	}



Thanks in advance

Hi,

You are creating $model outside foreach…

    $model = new PropertyPhoto;

so its created only one and storing always last upload only once…

I hope it will help…

Thank you it works B)