Uploadify (jQuery) + CI Sessions + CI Upload Class *Again* |
[eluser]~Chris~[/eluser]
I'm back! About 4 years ago I posted an article using codeigniter with swfupload, located here: http://ellislab.com/forums/viewthread/97399/ Well, things have changed and now we have Uploadify, which is awesome, and I noticed there were still some fairly recent replies to that other topic, so I thought I would write a new topic with how I'm doing it now, with Uploadify!. I believe its pretty secure, but I'm sure there are ways to make it even more secure. If your using Uploadifive, you can pretty much ignore this, as HTML5 doesnt have all the issues that the flash version of uploadify has. But if your using the Flash Based uploadify, its important to remember that flash has its own cookies and doesn't share them with the browser, so your sessions dont travel with the request made from the flash applet in Uploadify. Here is a solution to work with that. I will assume you you will be uploading an image, lets say a png file. This tut will revolve around that just to get you started, but of course is not limited to that. Configuration: In order for this to work you need to store the sessions in your database, make sure you have all the proper tables installed. I chose to encrypt my cookies, so make sure your encrypt key is set up. config/config.php Code: $config['sess_cookie_name'] = 'ci_session'; Uploadify sends all files (regardless of type) with the mimetype of application/octet-stream You need to add this mimetype to file extension or it will get rejected by the upload class. config/mimes.php Code: 'png' => array('image/png', 'image/x-png', 'application/octet-stream'), Extend the sessions class. We will have uploadify send an encrypted session id, and have the sessions class decode and use it if its present. libraries/MY_Session.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
[eluser]~Chris~[/eluser]
Controller: heres a snippet for your upload method. note that this can be in an authenticated controller, since the flash session will authenticate itself via the session id. Code: class UploadController extends CI_Controller { And finally, here is the the view snippet showing how to set up uploadify. Code: <div class="uploadify-queue" id="file-queue"></div> And there it is. Hope that helps people. There is even more you could do with that, but I will leave that up to your imagination. disclaimer* i didn't spell check, and i rarely uppercase my I's disclaimer2*: mmm just in case heres a license for the code written in this topic. http://opensource.org/licenses/OSL-3.0 Your free to use any code I've written: Attribution (to Chris Churchwell) is appreciated.
[eluser]TunaMaxx[/eluser]
This is a really timely follow-up; Glad to see you just posted in the last few months. Now to go try it out!
[eluser]Unknown[/eluser]
hi, chris. if I need to use swfupload, is the MY_Session class roughly the same? |
Welcome Guest, Not a member yet? Register Sign In |