【问题标题】:Krajee-bootstrap file input plugin:: How can i get the total number of the files from 'Drag & drop'?Krajee-bootstrap 文件输入插件:: 如何从“拖放”中获取文件总数?
【发布时间】:2016-03-26 00:55:23
【问题描述】:

我正在使用引导程序 - krajee file input plugin。在这里,我想获取从“在此处拖放文件”字段上传的文件总数。我在表单中包含了这个插件,所以当我点击提交按钮,如果文件没有上传,它应该显示错误消息。

              $("#file-1").fileinput({
                 uploadUrl: 'file/fileupload.php', 
                 allowedFileExtensions : ['jpg', 'jpeg','png'],
                 overwriteInitial: false,
                 maxFileSize: 1024,
                 maxFilesNum: 10,
             });


             $(".btn-warning").on('click', function()
             {
              if ($('#file-4').attr('disabled'))
              {
                $('#file-4').fileinput('enable');
              } 
              else
              {
                $('#file-4').fileinput('disable');
              }
            });  

这是上传前的图片

这是上传后

所以我需要检查这些图像是否已上传。

【问题讨论】:

    标签: javascript jquery file-upload input twitter-bootstrap-3


    【解决方案1】:

    $("#file-1").fileinput({
                     uploadUrl: 'file/fileupload.php', 
                     allowedFileExtensions : ['jpg', 'jpeg','png'],
                     overwriteInitial: false,
                     maxFileSize: 1024,
                     maxFilesNum: 10,
                 }).on('filebatchpreupload', function(event, data) {
        var n = data.files.length, files = n > 1 ? n + ' files' : 'one file';
        if (!window.confirm("Are you sure you want to upload " + files + "?")) {
            return {
                message: "Upload aborted!", // upload error message
                data:{} // any other data to send that can be referred in `filecustomerror`
            };
        }).on('fileuploaded', function(){
                alert("Upload completion message after plugin refresh.");
            });
    });

    【讨论】:

    • @RenjithVR 请检查上面的代码...更新。如果它不起作用,您可以删除 .on('filebatchpreupload', function(event, data) { var n = data.files.length, files = n > 1 ? n + 'files' : '一个文件'; 如果(!window.confirm("Are you sure you want to upload" + files + "?")) { return { message: "Upload aborted!", // 上传错误信息 data:{} // 任何其他要发送的数据可以在filecustomerror }; }) 中引用,看看其他 on 语句是否有效……好吗?
    猜你喜欢
    • 2015-05-01
    • 2015-09-01
    • 2018-10-27
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多