Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valums Ajax Upload with Codeigniter: Get Parameters!

How do I use paramaters with Valums Uploader and Codeigniter?

like image 528
Kevin Brown Avatar asked Jan 13 '11 21:01

Kevin Brown


4 Answers

With Valums the parameters are set like so:

var uploader = new qq.FileUploader({
    element: document.getElementById('file-uploader'),
    action: '/server-side.upload',
    // additional data to send, name-value pairs
    params: {
        param1: 'value1',
        param2: 'value2'
    }
});

or using

uploader.setParams({
   anotherParam: 'value' 
});

if you want it to be aware of the state of your app/

subD="/Pic"
function selectGaleryName()
{
subD=subD+"/3"
alert(subD) // /Pic/3
}


var uploader = new qq.FileUploader({
element: document.getElementById('UploadFile'),
action: 'http://localhost/Farainform/manager/upload.php'
// additional data to send, name-value pairs

onComplete: function(id, fileName, responseJSON){ 

selectGaleryName();

uploader.setParams({
  subDirectory : subD
});

},


});

if you want to set an id and a description for an image you can set these in javascript and then send these. So something like (im using jQuery here):

var description = $('#input_description').val(); //This can be an input 
var id = $('#input_description').att('id');

var uploader = new qq.FileUploader({
    element: document.getElementById('file-uploader'),
    action: '/server-side.upload',
    // additional data to send, name-value pairs
    params: {
        description: description,
        id: id
    }
});

Note I havent tested this code and its for demonstration purposes.

like image 196
Kieran Andrews Avatar answered Nov 15 '22 11:11

Kieran Andrews


$_GET was always destroyed in the 1.7.3 branch but upgrade to the new CodeIgniter Reactor 2.0 and you'll find that GET strings work out of the box.

When upgraded, use this syntax:

$this->input->get('value1');
like image 33
Phil Sturgeon Avatar answered Nov 15 '22 11:11

Phil Sturgeon


I don't know why it is not documented on Valums page, but apparently parameters should be sent not like this

params: {
        param1: 'value1',
        param2: 'value2'}

But like this

data: {param1: 'value1',
       param2: 'value2'}

On server side you could get them with $_REQUEST['param1'];

like image 26
Sver Avatar answered Nov 15 '22 10:11

Sver


You have to use PHP's input stream in order to obtain the data.

$fp = fopen('php://input', 'r');

Then read the data as you normally would with a regular file using fread(). Refer to valum's server side code located in server/php.php within the download.

like image 33
Austin White Avatar answered Nov 15 '22 11:11

Austin White