Upload A File Without Using Model


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

here is my controller:



         $uploadModel = new UploadForm;

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









and added these lines to my view:

	<div class="row">

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


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


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)


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

        if ($model->save())



    $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'); ?>


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

thanks a lot

i solve it by using this link