Plupload,动态更改url

时间:2011-10-06 09:59:58

标签: refresh plupload

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

如果选中该复选框,我想更改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个薄片,但在复选框更改时无法刷新网址中的压缩值。

我希望我的问题很明确,不要说英语很好。

感谢您的帮助

2 个答案:

答案 0 :(得分: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";
  }
});

答案 1 :(得分:1)

在plupolad v3 chaging settings.url将无效。你必须使用

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