Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Refine Tags

Snippets tagged "session upload" Snippets tagged "session upload"

Upload Multiple Files with Flash

you can create a multi-file uploader in Flash using ActionScript's FileReference and FileReferenceList classes, but you have to jump through some hoops to make it work. The upload() method doesn't send the user's session cookie with the request, so you have to send it in the URL and set the cookie manually on the server. If you are using ufo.js, the first argument to UFO.create() should look like this:

{
  movie: '/flash/uploader.swf', 
  id: 'uploader',
  name: 'uploader',
 
  flashvars: 'cookie=' + document.cookie,
 
  // other options ...
}
 

If you are dealing with multilple cookies, you need to parse document.cookie and send only the desired cookie.

Next, add the cookie to the URL:

var list:Array = myFileRefList.fileList;
var item:FileReference;
var url:String = _root.uploadURL + '?cookie=' + _root.cookie;
 
for (var i:Number = 0; i < list.length; i++) {
  item.upload (url);
}
 

Now add the following class to your symfony project:

class mySessionStorage extends sfSessionStorage
{
  public function initialize($context, $parameters = null)
  {
    if ( /* whatever the condition is when we want to do this */ ) {
      if ($cookie = $context->getRequest()->getParameter('cookie')) {
        $name = 'symfony';
        preg_match('/^' . $name.'=(.*)$/', $cookie, $asMatch);
        $value = $asMatch[1];
 
        session_name($name);
        session_id($value);
      }
    }
 
    parent::initialize($context, $parameters);
  }
}
 

Now edit factories.yml:

all:
  ...
  storage:
    class: mySessionStorage
    param:
      session_name: symfony
 

And you're done!

My blog post on this subject seemed popular, so I made it into a snippet. Hope it helps!

by Rob Rosenbaum on 2007-09-11, tagged flash  session  upload