I am completely perplexed, as I cannot ascertain a reason as to why this is not working. The code listed below works just fine when I use uploadify's default script:
$('#file_upload').uploadify({
'uploader' : '<?= base_url();?>js/uploadify/uploadify.swf',
'script' : '<?= base_url();?>js/uploadify/uploadify.php',
'cancelImg' : '<?= base_url();?>js/uploadify/cancel.png',
'queueID' : 'upload_queue',
'folder' : '/ths/images/buildings/',//be sure to check this value on the production site to make sure it's relative to the site root
'auto' : false,
'sizeLimit' : 1024000,
'multi' : true,
'removeCompleted': true,
'fileExt' : '*.jpg;*.gif;*.png;*.jpeg;',
'fileDesc' : 'Web Image Files (.JPG, .GIF, .PNG, .JPEG)',
'onAllComplete' : function(event, data) {
/*Code to update the page with results*/
}
});
However, as soon as I change the script to be something like
'script' : '<?= base_url();?>image/upload'
I get an error response back that says 'HTTP 302 error', even if all I do is copy the contents of the default Uploadify script to the controller method.
NOTE: I am using CodeIgniter, with mod_rewrite turned on in the .htaccess file to remove 'index.php' from the URL's. I am also using the database to manage the session. I don't know if any of this information will be useful, but I thought I'd include since these seem to have been important factors in other people's questions.
Uploadify doesn't pass the current session information (because it is Flash based) and so you are being redirected to your login script. If you inspect your log files, you'll see the user agent is different for the file post. You'll need to handle authorization differently from Uploadify to ignore your default session handler and inspect a parameter or other value.
You can pass a JSON array to post along with the file request. I use something like the following in my uploadify configuration file:
// abreviated javascript to pass data via uploadify
$('#element').uploadify({
'uploader' : '...',
...
'scriptData' : {"user_id":"1", "user_id_sig":"xxxxx"},
...
'onAllComplete' : function(){ ... }
});
You can generate that with:
// create the signature value
$a_secret_string = 'abc123';
print json_encode(array(
'user_id' => $user_id,
'user_id_sig' => md5($user_id . $a_secret_string),
));
In the upload method of the controller, inspect that the sig + user_id value check out and pull the necessary session information from the DB at that time.
// check the signature value
$a_secret_string = 'abc123';
if(md5($_REQUEST['user_id'] . $a_secret_string) == $_REQUEST['user_id_sig']){
// do the upload
} else {
// handle the error
}