Upload A File Without Using Model

hi

by using this linki tried to save an uploaded image but i got error:

here is my controller:




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

		{

         $uploadModel = new UploadForm;

         $uploadModel->upload_file = CUploadedFile::getInstance($uploadModel,'image');

         $uploadModel->upload_file->save("C:\\".$uploadModel->upload_file->name);

         

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

			if($model->save()){

            

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

         }

		}



and added these lines to my view:




	<div class="row">

      <input type="file" name="image"/>

	</div>



and here is the error msg:




Fatal error: Call to a member function save() on a non-object in C:\xampp\htdocs\sd\protected\controllers\CategoryController.php on line 57



thanks…

Your controller should look more like this:




public function actionUpdate($id)

{

    $model = SomeClass::model()->findByPk($id);


    if ($model === null)

        throw new CHttpException(404, 'Model not found');


    $uploadModel = new UploadForm;


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

    {

        $uploadModel->upload_file = CUploadedFile::getInstance($uploadModel, 'upload_file');


        if ($uploadModel->upload_file)

            $uploadModel->upload_file->saveAs('some/location');


        $model->attributes = $_POST['SomeClass']


        if ($model->save())

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

    }


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

}



Your view should look more like this:




    <?= CHtml::beginForm('', 'post', array('enctype'=>'multipart/form-data')); ?>


    ...


    <div class="row">

        <?= CHtml::activeFileField($uploadModel, 'upload_file'); ?>

    </div>


    <?= CHtml::endForm(); ?>



thanks a lot

i solve it by using this link