'How to send additional data using PLupload?

I'm using plupload to make an ajax file uploading. Now the plupload.Uploader class has many options but none are additional data.

For Example :

var uploader = new plupload.Uploader({
    runtimes : 'gears,html5,flash,silverlight,browserplus',
    browse_button : 'pickfiles',
    container : 'contact_container',
    max_file_size : '10mb',
    url : 'upload.php',
    flash_swf_url : '/plupload/js/plupload.flash.swf',
    silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
    filters : [
        {title : "Image files", extensions : "jpg,gif,png"},
        {title : "Zip files", extensions : "zip"}
    ],
    resize : {width : 320, height : 240, quality : 90}
});

What i'm trying to achive is i have a folder in my server where all the uploads are being saved. I neeed inside the folder to create a sub-folder to each user that have uploaded files there. How can i add data like id of the user to the instance of plupload.Uploader? Or if i'll wrap a form inside the container div, will i be able to see it in the $_REQUEST? Or is there some other way i can achive this?



Solution 1:[1]

You can use uploader.settings.multipart_params["name1"] = yourValue; but "name1" must be declared in uploader config :

multipart_params : {
    "name1" : "value1",
    "name2" : "value2"
}

Solution 2:[2]

If you need to dynamically add parameters on every file upload you can do this:

uploader.bind('BeforeUpload', function(up, file) {
    up.settings.multipart_params = {

        "parameter1": "value1",
        "paremeter2": "value2"

    };
});

Solution 3:[3]

You can also use

uploader.settings.url = "upload.php?param1=whatever"

and just pass it as a get variable.

Solution 4:[4]

More up to date for 3.xx After files added use this as an example with DEPOSITImageUploader being the declared plupload change as you wish

BeforeUpload: function (up, files) {
            console.log("BEFORE UPLOAD ");
            var settings = DEPOSITImageUploader.settings;
            var params = settings.multipart_params;
            $.extend(up.settings.params, { deposit_id : $('#deposit_id').val() });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GDP
Solution 2 Agu Dondo
Solution 3 AJNeufeld
Solution 4 Gary