2

我正在使用 plupload,JQuery UI 实现。我正在尝试将其他参数传递给服务器,但我无法使其工作。应该很简单,在函数执行时参数已经设置好了,所以这应该不是问题。我试过这个:

function GetPlUploader(m)
{
$("#divOpplaster").plupload(
{
    // General settings
    runtimes: 'flash,html5,silverlight',
    url: 'upload.php',
    max_file_size: '10mb',
    chunk_size: '1mb',
    unique_names: true,
    multipart: true,
    multipart_params: [
    {
        'ordre': ordreibruk,
        'mode': m}
    ],

    // Specify what files to browse for
    filters: [
    {
        title: "Bildefiler",
        extensions: "jpg,gif,png,bmp"}
    ],

    // Flash settings
    flash_swf_url: 'plupload/js/plupload.flash.swf',

    // Silverlight settings
    silverlight_xap_url: 'plupload/js/plupload.silverlight.xap',

    init: {
        FileUploaded: function(up, file, info)
        {
            // Called when a file has finished uploading
            console.log('[FileUploaded] File:', file, "Info:", info);
        }
    }
});

console.log("Ordre: " + ordreibruk + ". Mode: " + m)

$("#divOpplaster").dialog(
{
    autoOpen: false,
    width: 650,
    show: "fade",
    hide: "fade"
})

$("#divOpplaster").dialog("open")

// Client side form validation
$('form').submit(function(e)
{
    var uploader = $('#uploader').plupload('getUploader');

    // Files in queue upload them first
    if (uploader.files.length > 0)
    {
        // When all files are uploaded submit form
        uploader.bind('StateChanged', function()
        {
            if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed))
            {
                $('form')[0].submit();
            }
        });

        uploader.start();
    }
    else
    alert('Du må velge minst én fil for opplasting.');

    return false;
});
}

我也尝试在 $('form').submit 部分添加它:

uploader.bind('BeforeUpload', function(up)
    {
    up.settings.multipart_params =
    {
        'ordre': ordreibruk,
        'mode': m
    };

});

但无济于事。

我确定我忽略了一些非常简单的事情,但是什么?

亲切的问候,安德斯

4

2 回答 2

4

I must confess I use to put my parameters as query string parameters in the url :

  • during init : url: '/upload.aspx?id='+Id,
  • or later : upldr.settings.url = upldr.settings.url + '&token=' + myToken;

It works fine. Hope this will help

于 2012-11-14T15:55:36.560 回答
0

有同样的问题。偶然发现了这个片段,它可以很容易地翻译成咖啡脚本,也适用于我的项目。允许您在初始化后传递多部分参数(例如,在点击上传之前字段可以更改的情况)

var myUploader = $('#uploader').plupload('getUploader');
myUploader.bind('BeforeUpload', function(up, file) {
    up.settings.multipart_params = {path : $("#path").val()};
});

在您完成 $("#divOpplaster").plupload(...) 的正常初始化和设置后调用它(当然,将您的 ID 设置为您的上传者字段)

于 2015-03-01T03:09:10.537 回答