CHttpSession Error


I’m currently working on an fileupload system powered with JUpload (

But when I try to save my filename to a session variabele, I get a 500 error in my trace log:

[php] Indirect modification of overloaded element of CHttpSession has no effect (filename)

this is my code:

public function actionProcessupload()


        Yii::trace(strrev(dirname(__FILE__)), 't');

        $basePath = strrev(strstr(substr(strstr(strrev(dirname(__FILE__)),DIRECTORY_SEPARATOR),1),DIRECTORY_SEPARATOR));




			$session = new CHttpSession;

			$session['file'] = array();

            foreach($_FILES as $file => $fileData)



                $uploadedFile = CUploadedFile::getInstanceByName($file);

                if($uploadedFile === null)


                    Yii::trace('no file found', 'system.upload');


                    Yii::trace('file found', 'system.upload');

                   Yii::trace($uploadedFile->getName(). " ". $uploadedFile->getTempName()." ".$uploadedFile->getError(), 'system.upload');

                   if($uploadedFile->saveAs($basePath.DIRECTORY_SEPARATOR.Yii::app()->params['photoDir'].DIRECTORY_SEPARATOR.$uploadedFile->getName()) === true)


                       Yii::trace('Save successed','system');



                       Yii::trace('Save failed', 'system');






            echo "SUCCESS";




The exceptions comes from the line that does the array_push.


Session autostart is on in app config:





		'session' => array(

			'autoStart'=> true



First, you don't need to create a new instance of CHttpSession. You can get the session component via Yii::app()->session.

There could be some problem when you use $session['file'] like this way, depending on your PHP version. A safe approach is to use a temporary array variable and then assign it to the session variable at the end.

Aah, thanks, I solved the problem with the add function of CHttpSession.

A little other question: isn't there a component in Yii to easy resize and crop images?

No currently. At this moment, we are trying to make the framework core more stable and extensible. Features like image resizing are put at very low priority since they can be accomplished with third party code easily.