![]() |
Using SWFUpload + Sessions + upload class, how I did it. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using SWFUpload + Sessions + upload class, how I did it. (/showthread.php?tid=13334) |
Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 11-19-2008 [eluser]~Chris~[/eluser] Newer Version HERE! http://ellislab.com/forums/viewthread/221152/ Hello everyone. I have been a member for some time, and I have used the forums many times to solve many a problem, but I haven't really contributed much. I usually just find my solution and move on. SwfUploader is something I have been playing around with for a while now, but never did find a solid implementation to keep the sessions when I uploaded files. Well I finally figured out a solution that fits me, and I think works very well. I thought I would post about it and maybe help someone else out, considering this has been a fustrating topic for many. So here is my implementation: Let me start out by saying that you must be using the native session library. It can be found in the wiki. By allowing your sessions to be handled by php, you can pick up the session in from the "flash" useragent. I modified the native session library. I figured it was ok, considering by using the native session library, I am still not changing the core code. First of all, to use the swfUploader with the code igniter upload class, you need to add the appropriate mime types. /system/application/config/mimes.php Code: 'jpeg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'), Next you need to modify the native sessions library what we will do is enable a paramater for the session id, and if the session id is set, then we will tell the php session to use that session id, instead of trying to create a new one for the new useragent when flash accesses the upload script. /system/application/libraries/Session.php (roughly line 31) Code: //Add $params = array() as a parameter /system/application/libraries/Session.php (roughly line 146) Code: //again, here, I add a parameter $phpsessid and give it a default of null, so it is reverse if the paramater is set (it should be a session id) then we tell php to start the session using that session id. Now you can use the current session data with swf upload while using the upload class, which I will also demonstrate. The Controller (/system/application/controllers/fileupload.php Code: class Fileupload extends Controller { Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 11-19-2008 [eluser]~Chris~[/eluser] the view (/system/application/views/uploadform.php) Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> All the included files would be the demonstration files that you can download with swfuploader. Now, my personal code looks much different, so i stripped a lot out and made it basic. I havent tested this exact code, so you may need to debug it. It is just examples anway. in the sessions class, you could even tell it to automatically load the session id if its posted, then you could autoload the sessions class, instead of having to call it. Anyway, there it is. Hope it helps. Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 12-06-2008 [eluser]omed habib[/eluser] Chris, First off, this was an absolutely and positively amazing job. Thank you!!! Second, it should be worth noting that: 1. The session library CANNOT be autoloaded in the config/autoload.php file for this to work (or anywhere else for that matter, CI will just ignore the second attempt) 2. In the controller Fileupload::upload() , you need to set the upload config parameters BEFORE you load the upload library... 3. ... and then when you do load the upload library, you need to pass those configs as an argument: Code: // Set upload path Other than that... I can attest that this method also works for the latest version of SWFUpload v.2.2.0 Beta 3 release. However, I ignored everything in the view file except for the post params: Code: post_params: {"PHPSESSID" : "<?=$this->session->userdata('session_id')?>"}, Thank you for your contribution!! Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 02-06-2009 [eluser]~Chris~[/eluser] Late Response, right? LOL. I wasn't clear in what I said. What I meant was: You could actually modify the script a little bit, if you wanted, in order to use it with autoload. Simply by checking if PHPSESSID exists in the POST array, and using it if it does in the sessions library. And it could continue on to start up sessions normally if there was no phpsessid in the post array. haha, and yes, the parameters need to go before you load the library. My mistake. I must have zoned when I wrote that part. Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 02-06-2009 [eluser]Jupiter[/eluser] One important remark: when using SWFUpload from a Mac, it appends the port :80 to your upload URL. Be sure to sanitize this in case you pull it from $_SERVER['HTTP_HOST'] and do someting with it in your script. Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 03-12-2009 [eluser]CollinsSolutions[/eluser] i am trying this same implementation but instead of uploading i am uploading to a database. Its not working for me. Here is my code Code: //you should have swfuploader POST your session id (youll see in the view) Any ideas? Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 03-12-2009 [eluser]pistolPete[/eluser] [quote author="CollinsSolutions" date="1236903951"]Its not working for me[/quote] Give a better error description. Are you using native PHP sessions? What's your database layout? ... Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 03-12-2009 [eluser]CollinsSolutions[/eluser] i think its native sessions. Database layout inst the problem. That i had working with standard uploader, its the SWF that's not working. Since its flash its hard to debug since there is no redirecting to the page to output anything. Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 03-12-2009 [eluser]pistolPete[/eluser] Use the debug setting of SWFupload: http://demo.swfupload.org/Documentation/ Code: (...) Additionally use Firebug: http://www.getfirebug.com Using SWFUpload + Sessions + upload class, how I did it. - El Forum - 03-12-2009 [eluser]CollinsSolutions[/eluser] that helped it looks like its uploading fine i am just not picking it up to post it to the database in php. Is there a way to write to that log from my upload function? |