6

在 plupload div 之后,我有一个带有 plupload 的上传表单和一个带有布尔值的复选框。

如果选中该复选框,我想更改 plupload 中 url 的值。

这是我的代码

<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();
    }
});

});

url 变量的值是在第一次加载页面时使用压缩值定义的。我尝试了 1000 次但无法在复选框更改时刷新 url 中的压缩值。

我希望我的问题很清楚,不要说英语很好。

感谢帮助

4

2 回答 2

22

只需绑定到“BeforeUpload”事件,您就可以更改 uploader.settings 以满足您的需求。

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";
  }
});
于 2011-10-20T21:55:58.160 回答
2

在 plupolid v3 中,chagingsettings.url不起作用。你必须使用

uploader.setOption('url', 'your/url/here');
于 2016-12-07T13:33:48.733 回答