views:

47

answers:

1

Howdy,

First of all, I'm using KohanaPHP Framework.

I've impletemented SWFUpload successfully, working quite nice. I'm having only one issue.

The main problem is I need to allow users to upload attachments before submitting form. So I decided to use Session var to store attachments array. Unfortunately, it is working inly if I use HTML upload (based on iframe), but not when I use SWFUpload.

I tried to Google for that, but without any working solution. Any ideas?

Update & Solution
Basically, I didn't know there's an issue with Flash and sessions. Providing the same session id didn't helped me because I got unlogged. Anyway I got a solution for people with the same issue.

I created an unique ID of an item. I upload files to temporary directory, then... I'm scanning this directory and I'm adding uploaded filenames to session.

Tom

+2  A: 

What you need to is pass the session id to SWFUpload by hand. In a nutshell, you do this in your template:

<script type="text/javascript">
var PHPSESSID = <?php echo json_encode(session_id()); ?>;
</script>

Then you do this with your SWFUpload code:

var settings = {
   post_params: {"PHPSESSID" : PHPSESSID},
   /* the rest of the settings */
};

And finally, in your application code, before you call session_start, you need to do this (usually just in your index.php or whatever bootstrap you use):

// Restore session that came from SWFUpload
if(isset($_REQUEST['PHPSESSID']))
    session_id($_REQUEST['PHPSESSID']);

After this session_start() will use the correct session even for SWFUpload requests.

reko_t
@reko_t - I'll try your suggestions and will let you know if they works.
Tom
Hm...after putting `if(isset($_REQUEST['PHPSESSID'])) session_id($_REQUEST['PHPSESSID']);` in Session library I get unlogged? Any suggestions? :)
Tom
Is it before _any_ other session code (it absolutely *has* to be the first session related function you use).
reko_t
Basically, I've put this into Kohana Session library, in create() method, before session_start().
Tom
Thanks. Your answer did not resolve my issue **but** it gives an idea. I implement a solution and it's working so I'm gonna to mark your answer as correct cause it was working on pure PHP code (without using any framework).
Tom