【问题标题】:Limit the number of files that can be selected before uploading when using Plupload限制使用 Plupload 时上传前可选择的文件数
【发布时间】:2014-11-09 16:48:50
【问题描述】:

我正在使用Plupload 将文件上传到我的网站。我正在尝试限制在上传之前可以选择的文件数量。我尝试将multi_selection 设置为false,这部分有效。但是,如果您单击“选择文件”并通过文件资源管理器选择一个文件,等待文件资源管理器关闭,然后单击“选择文件”并再次执行相同操作,则可以选择多个文件。

如何在上传前只选择一个文件?

这是我正在使用的代码的演示:http://jsfiddle.net/5j8c05j9/

【问题讨论】:

标签: javascript jquery plupload


【解决方案1】:

基于此问题的答案:jQuery Plupload restrict number of uploads

您可以在plupload中添加以下属性:

max_files: 1,

然后修改FilesAdded函数,如下:

FilesAdded: function(up, files) {
    plupload.each(files, function(file) {
        // if there are more files than the allowed  
        if (up.files.length > up.settings.max_files) {
            // display alert message
            alert('Cannot send more than ' + up.settings.max_files + ' file(s).');

            // here you can also hide the "Select Files" button with the following code
            //$(up.settings.browse_button).hide();

            // cancel adding files. break each.
            return false;
        }
        document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
    });
},

看看你的updated jsfiddle

【讨论】:

    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 2018-04-05
    • 2013-11-21
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    相关资源
    最近更新 更多