[SOLVED] Uploadify and session problems

Uploadify is a wonderful plugin for jQuery that allows you to upload several files at once,  it does the uploads transparently  using flash (take a look at the demo on this link).

In fact, the great advantage I see is not to be able to upload several files at once, this can be done by javascript with no extra plugins, the great advantage is the progress bar it shows to the user, which is great for obvious usability reasons (user looking a screen where nothing happens… not good :p).

Apart of uploading files, you can also upload any other variables or data (take a look to scriptData). This can be really useful if you want, for example,to send the data in another form at the same time a file is being uploaded.

The great disadvantage of uploadify, is that each file is sent in a separate request. This means that if you are uplading 30 files, each file is sent in a separate HTTP request. Please note that the problem here is not the speed, because you can easily make uploadify sends several files at once, in parallel, the problem appears if you have to send form data on the first request only… The fact that are different requests makes things a little more difficult to handle on the server, but anyway, this only happens on specific cases…

Anyway, I recently used uploadify in a project where users should be logged in, in order to upload files. The thing is, when I first tried uploadify, it didn’t work… files were being apparently uploaded, but they were not stored in the server. I tried again and again, and the same problem… Finally I discovered why.

Uploadify does not send cookies, and because of that, it cannot send session information on the request, so the server does not know that the user sending the files is registered, it thinks it’s an annonymous user. The good thing, is that once I realiced what was the problem, the solution was quite simple.

The solution to keep the session using uploadify is the same as when the client cannot store cookies. Basically is just adding session name and identifier at the end of the URL, as a GET request.

In PHP, adding session to the URL would be something like:

$url = $url . '?' . session_name() . '=' . session_id();

Once I did that, the application was working with uploadify 😉

Trackback URL

, , , ,

  1. Max
    18/11/2010 at 1:20 am Permalink

    Hi, I think I might have the same problem for my implementation. I am integrating uploadify into wordpress, and when try and upload a file I get http:403 and io error #2038. Would that be because wordpress cookies have not been send with the data? I see you use wordpress for your website, have you tryed implementing uplodify (or similar progress bar for uploads) on wordpress?

  2. Pau Sánchez
    24/11/2010 at 4:44 pm Permalink

    I never tried uploadify on wordpress I’m sorry.

  3. Dom
    25/03/2011 at 10:33 am Permalink

    Hello , the session variables I am using are supposed to be secure like user ids and what not so I dont want to send it using script data. This looks like a good alternative but my question is Wouldnt this be a bi security issue by letting the client side see these session ids and names. My problem is that I dont want people to hijack my site and upload millions of photos to someones account on my website

  4. Kim
    10/06/2011 at 11:15 am Permalink


    The PHP session variable is sent as a HTTP header anyway, so it’s not actually a secret. However, the session data is stored on your server. Session hijacking involves stealing another client’s session ID, and is not an issue in this case, as the session ID is sent from your client.

  5. Edd
    09/09/2011 at 3:29 am Permalink

    This does not work because uploadify does not let you set GET variables in the script parameter;

    var php_session_name=””;
    var php_session_id=””;
    ‘script’: ‘/upload.php&’ + php_session_name + ‘=’ + php_session_id

    When uploadify.swf makes it’s ajax call, it removes the GET variables and they never end up server side. How am I supposed to be passing the session vars to uploadify so that it will use them as GET vars when it uploads?

  6. marco
    13/09/2011 at 8:24 pm Permalink

    i usually use framwork jquery ajax, to upload progress…. but it’s very easy…