Where did the uploaded file go?

Hi all,

I was testing out how to upload a file as per this example


(BTW it should say CUploadedFile not CUploadFile)

It seems to be doing something but I know not what. Where did the file I “uploaded” go? I’m working on “localhost”.

THe print_r($model) says

"Pic Object ( [image] => CUploadedFile Object ( [_name:private] => diver.jpg [_tempName:private] => C:\PROGRA~1\EASYPH~1.0B1\\tmp\php563.tmp [_type:private] => image/jpeg [_size:private] => 23136 [_error:private] => 0 [_e:private] => [_m:private] => ) [_errors:private] => Array ( ) [_validators:private] => [_scenario:private] => [_e:private] => [_m:private] => ) "

I think it got the filename right, but that’s all I could tell.

My code :

//in the Models/Pic.php

class Pic extends CFormModel


public $image;

public function rules()


	return array('image', 'file', 'types'=>'jpg');





//in the Controllers/PicController.php

class PicController extends CController


    public function actionCreate()


        $model=new Pic;






            //CFormModel does not have a Save method? but has a SaveAs?


                // redirect to success page

            echo "success?";




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



and the View is just:

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


<?php echo CHtml::activeFileField($model, 'image'); ?>


<?php echo CHtml::submitButton('Create', array('submit'=> 'Create')) ; ?>

<?php echo CHtml::endForm(); ?>

The image file "diver.jpg" does not appear in the folder? What happened? What did the code do?


I read the comments and noticed that the first one said:

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

// As others have noted: $model->image at the end of the path is required,    // and is the filename of your image


Is trying to save an image as a folder ??




You can also define your path as a named constant

define("PATH_UPLOAD_IMAGE",     "/upload/");


// it's an example, define ABSOLUTE_PATH_UPLOAD_IMAGE as your needs

And use it like Gustavo and beninblack:



Thanks guys, it works now!

Somebody should go fix the errors in the tutorial though! Yii is hard enough as it is. :)

Can you give more details… link to the doc… and what is written wrongly…