How to uploadify and session

Hi folks,

First I’ll try to explain what I’m trying to do:

  • A have a create ad form where user can input some information about the advertising and upload related images.

  • I have two models: Ad and AdPhoto (which in terms of table are one-to-many)

  • I want to present the input data and upload widget at the same page.

  • The user must upload related images (using ajax) before save the advertising data… so I have to store the uploaded images in some "staging area" and show then. so that the user can type a legend for each image.

  • When the user click the "save button" the application saves the Ad data, and get the related images from "staging area" to the permanent area and persist it data to database.

I’m trying uploadify extension and the upload part works Ok.

My view:




    'options'=> array(

    'script' => $this->createUrl('realtyPhoto/upload'),

    'cancelImg' => Yii::app()->baseUrl.'/images/cancel.png',

    'auto' => true,

    'multi' => true,

    'scriptData' => array('PHPSESSID' => session_id()),

    'fileExt' => '*.jpg;*.png;*.bmp;*.jpeg',

    'buttonText' => 'Enviar fotos',

    'buttonImg' => Yii::app()->baseUrl.'/images/botao_upload.gif',

    'width' => 190,

    'height' => 33,


  'callbacks' => array(

    'onError' => 'function(evt,queueId,fileObj,errorObj){alert("Error: " + errorObj.type + "\nInfo: " +;}',

    'onComplete' => 'function(){ $("#displayPhotos").load(\''.$this->createUrl("/realtyPhoto/loadTemporary", array("sessid"=>session_id())).'\'); }',

    'onCancel' => 'function(evt,queueId,fileObj,data){alert("Cancelled");}',



The staging area:

When the image is uploaded I call [font="Courier New"]realtyPhoto/upload[/font] which must proccess the uploaded file and store it in some temporary directory (this is working Ok).

public function actionUpload()


  Yii::app()->session->add('my_var', 'related image');


To know how uploaded photos belongs to each user I’m trying to store data into a session var, using: [font=“Courier New”]Yii::app()->session->add(‘my_var’,$uploadedData);[/font]

But when the upload is Ok, onComplete callback function is called and [font="Courier New"]realtyPhoto/loadTemporary[/font] is executed.

The session var that I set when [font="Courier New"]realtyPhoto/upload[/font] was called isnt present.

public function actionLoadTemporary()



    echo 'Ok.. my_var is present.';


    echo 'ERROR: my_var isnt present.';

  echo 'DUMPING _SESSION<br>';

  echo CVarDump::dumpAsString($_SESSION);

  echo 'DUMPING Yii::app()->session->toArray()<br>';

  echo CVarDump::dumpAsString(Yii::app()->session->toArray());


The crazy part is: if I type on the address bar [font=“Courier New”]index.php?r=realtyPhoto/upload[/font] and then [font=“Courier New”]index.php?r=realtyPhoto/loadTemporary[/font] the session var is present, but when I run through the uploadify plugin it doesn’t work !

If someone have any better ideia to deal with this problem, i’ll really appreciate.

I’d this problem once

uploadify is a flash component so when it posts the files for you it doesnt contain a session variable

You can fix this by sending the session id to the flash component, and make it return as a get variable, then you set up session_id based on this value received from the get variable

use some kind of hash to pass the id in the url securely

@Gustavo thanks for the tip. It solve my problem ;)

I’m having the same problem, could you please post your solution here ?

I was following this but i get this error

The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'

I think it’s session_start problem, but track back my phpsessID, it matches a-z0-9{32}

Please help.