Uploading Image Where Allow Empty Is True But There Is Fatal Error

Hallo guys, i have a little problem i hope someone will help me out

Fatal error: Call to a member function saveas() on a non-object in C:\wamp\www\writing\protected\controllers\OrdersController.php on line 77

i have tried to debug the code but i can’t seem to get where im going wrong.


public function actionCreate()

	{

		$model=new Orders;


		// Uncomment the following line if AJAX validation is needed

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

		

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

		{

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

			$file = CUploadedFile::getInstance($model, 'attachment');

			$model->attachment = $file;

			if($model->save()){

				$path = Yii::getPathOfAlias('webroot'). "/uploads/" .$model->attachment;

				$file->saveas($path);

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

			}

		}


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

			'model'=>$model,

		));

	}

please help

CUploadedFile::getInstance() documentation:

thanks for the tip, with this i made changes to my code like this and now it works good


public function actionCreate()

	{

		$model=new Orders;


		// Uncomment the following line if AJAX validation is needed

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

		

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

		{

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

			$file = CUploadedFile::getInstance($model, 'attachment');

			$model->attachment = $file;

			if($model->save()){

				if($file!=null){

					$path = Yii::getPathOfAlias('webroot'). "/uploads/" .$model->attachment;

					$file->saveas($path);

				}

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

			}

		}


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

			'model'=>$model,

		));

	}

then there is this part in the order model


....................

array('attachment','file','types'=>'docx,doc,pdf','allowEmpty' => true),

...................