Plupload dynamically change url

I have a upload form with plupload and a checkbox with a boolean after the plupload div.

I want to change the url value in plupload if the checkbox is checked.

Here is my code

<div id="uploader"> <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p> </div> <input id="compressFiles" type="checkbox" name="compressFiles" style="margin:10px 0 0 10px;" value="compress" checked="checked" /> $(function() { $("#compressFiles").change(function(){ if( $("#compressFiles").is(':checked') ){ compress = 'compress'; } else{ compress = 'no'; } }) $("#uploader").plupload({ runtimes : 'gears,flash,html5,html4,browserplus,silverlight', url: 'uploadHandler.php?compressFiles=' + compress, max_file_size : '1000mb', max_file_count: 20, // user can add no more then 20 files at a time unique_names : true, dragdrop : true, multiple_queues : true, // Addeb by LG - problem with FF filters: [ {title: "All", extensions: "*"} ], // Rename files by clicking on their titles rename: true, // Sort files sortable: true, // Flash settings flash_swf_url : 'js/plupload.flash.swf', // Silverlight settings silverlight_xap_url : 'js/plupload.silverlight.xap', init : { FilesAdded: function(up) { if( $("#compressFiles").is(':checked') ){ compress = "no" } else{ compress = "no" } } } }); // Client side form validation $('form').submit(function(e) { var uploader = $('#uploader').plupload('getUploader'); // Validate number of uploaded files if (uploader.total.uploaded == 0) { // Files in queue upload them first if (uploader.files.length > 0) { // When all files are uploaded submit form uploader.bind('UploadProgress', function() { if (uploader.total.uploaded == uploader.files.length){ alert("coucou"); $('form').submit();} }); uploader.start(); } else alert('You must at least upload one file.'); e.preventDefault(); } }); }); 

The value of the url variable is determined by the initial loading of the page using the compression value. I tried 1000 thin ones, but could not update the compression value in the URL when changing the checkbox.

I hope that my problem is understandable, does not speak English very well.

thanks for the help

+6
source share
2 answers

Just bind to the "BeforeUpload" event, and you can change the uploader.settings settings to suit your needs.

 this.uploader.bind('BeforeUpload', function(uploader, file) { if($("#compressFiles").is(':checked')) { uploader.settings.url = "uploadHandler.php?compressFiles=compress"; } else { uploader.settings.url = "uploadHandler.php?compressFiles=no"; } }); 
+22
source

In plupolad v3 chaging settings.url will not work. You have to use

 uploader.setOption('url', 'your/url/here'); 
+1
source

Source: https://habr.com/ru/post/898747/


All Articles