How to send additional data using PLupload?

后端 未结 4 515
星月不相逢
星月不相逢 2020-12-13 06:25

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          


        
相关标签:
4条回答
  • 2020-12-13 06:35

    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"
    
        };
    });
    
    0 讨论(0)
  • 2020-12-13 06:49

    Have you tried using the setting for multipart_params? Add an additional option to your plupload.Uploader like so:

    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},
        multipart_params : {
            "name1" : "value1",
            "name2" : "value2"
        }
    });
    

    You will then need to process the values in the file that handles the upload (upload.php by default). I think the values are captured by $_POST but you can use $_REQUEST just to be sure.

    I've used jQuery to assign values on the fly, so instead of "name1" : "value1" you can use something like "name1" : $("#name1").val(), where #name1 might be an input elsewhere on the page.

    Plupload's documentation is a little sparse for some of these settings.

    0 讨论(0)
  • 2020-12-13 06:53

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

    multipart_params : {
        "name1" : "value1",
        "name2" : "value2"
    }
    
    0 讨论(0)
  • 2020-12-13 06:57

    You can also use

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

    and just pass it as a get variable.

    0 讨论(0)
提交回复
热议问题