如何使用blueimp文件上传插件只上传一次文件? [英] How to upload a file only once with blueimp file upload plugin?

查看:32
本文介绍了如何使用blueimp文件上传插件只上传一次文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 bluimp jQuery-File-Upload-plugin .选择一些文件并上传它们没有问题,但是当我想在不刷新页面的情况下上传另一个文件时,第一个文件又被上传了.我的问题是如何在上传文件后取消设置"文件.这是我的源代码

Javascript:

$('#MappeFile').fileupload({数据类型:'json',自动上传:假,maxNumberOfFiles : 未定义,最大文件大小:6000000,最小文件大小:未定义,接受文件类型:/.+$/i,url : "/ajax/UploadFile.php",添加:函数(e,数据){$("#testUploadButton").on("click", function() {$('#progress .bar').show();如果 ($.browser.msie && parseInt($.browser.version, 10) <10) {$('#progress .bar').css({"background" : "url(images/progressbar.gif) 不重复",宽度":100%"})} 别的 {$('#progress .bar').css({'背景颜色':#2694E8",宽度":0%"});}数据提交();})},变化:函数(e,数据){$.each(data.files, function(index, file) {console.info('选择的文件:' + file.name);文件计数++;});},丢弃:函数(e,数据){$.each(data.files, function(index, file) {console.info('选择的文件:' + file.name);文件计数++;});},完成:功能(e,数据){$.each(data.result, function(index, file) {vOutput = "";vOutput += ""+ 文件 + "</td>";vOutput += "";$("#MappeFileListe").append(vOutput);文件上传++;if (filesCount == filesUploaded) {上传的文件 = 0;文件数=0;$('#progress .bar').hide();}});},进度:函数(e,数据){var progress = parseInt(data.loaded/data.total * 100, 10);$('#progress .bar').css('width', progress + '%');}});

HTML:

<form id="MappeFile"><input type="file" id="MappeFileSelect" name="files[]" data-url="ajax/UploadFile.php" multiple/><div id="进度"><div class="bar" style="width: 0%;"></div>

<input type="button" class="neuButton" value="upload" id="testUploadButton"/></表单><table id="MappeFileListe"></table>

解决方案

我自己找到了答案——上传后解绑按钮的点击事件就够了:

add : function(e, data) {$("#testUploadButton").on("click", function() {$('#progress .bar').show();如果 ($.browser.msie && parseInt($.browser.version, 10) <10) {$('#progress .bar').css({"background" : "url(images/progressbar.gif) 不重复",宽度":100%"})} 别的 {$('#progress .bar').css({'背景颜色':#2694E8",宽度":0%"});}数据提交();$("#testUploadButton").off("点击")})},

I'm using the bluimp jQuery-File-Upload-plugin . It's no problem to select some files and upload them, but when I want to upload another files without refreshing the page, the first ones are getting uploaded again. My question is how can I "unset" files after they are uploaded. Here is my sourcecode

Javascript:

$('#MappeFile').fileupload({
        dataType : 'json',
        autoUpload : false,
        maxNumberOfFiles : undefined,
        maxFileSize : 6000000,
        minFileSize : undefined,
        acceptFileTypes : /.+$/i,
        url : "/ajax/UploadFile.php",
        add : function(e, data) {
            $("#testUploadButton").on("click", function() {
                    $('#progress .bar').show();
                    if ($.browser.msie && parseInt($.browser.version, 10) < 10) {
                        $('#progress .bar').css({
                            "background" : "url(images/progressbar.gif) no-repeat",
                            "width" : "100%"
                        })
                    } else {
                        $('#progress .bar').css({
                            'background-color' : "#2694E8",
                            'width' : '0%'
                        });
                    }
                data.submit();
            })
        },
        change : function(e, data) {
            $.each(data.files, function(index, file) {
                console.info('Selected file: ' + file.name);
                filesCount++;
            });
        },
        drop: function(e, data) {
            $.each(data.files, function(index, file) {
                console.info('Selected file: ' + file.name);
                filesCount++;
            });
        },
        done : function(e, data) {
            $.each(data.result, function(index, file) {
                vOutput = "<tr>";
                vOutput += "<td>" + file + "</td>";
                vOutput += "<tr>";
                $("#MappeFileListe").append(vOutput);
                filesUploaded++;
                if (filesCount == filesUploaded) {
                    filesUploaded = 0;
                    filesCount=0;
                    $('#progress .bar').hide();
                }
            });
        },
        progressall : function(e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .bar').css('width', progress + '%');
        }
    });

HTML:

<div id="KundeMappe">
    <form id="MappeFile">
        <input type="file" id="MappeFileSelect" name="files[]" data-url="ajax/UploadFile.php" multiple/>
        <div id="progress">
            <div class="bar" style="width: 0%;"></div>
        </div>
        <input type="button" class="neuButton" value="upload" id="testUploadButton"/>
    </form>
    <table id="MappeFileListe"></table>
</div>

解决方案

I found the answer myself - It's enough to unbind the click event of the button after upload:

add : function(e, data) {
            $("#testUploadButton").on("click", function() {
                    $('#progress .bar').show();
                    if ($.browser.msie && parseInt($.browser.version, 10) < 10) {
                        $('#progress .bar').css({
                            "background" : "url(images/progressbar.gif) no-repeat",
                            "width" : "100%"
                        })
                    } else {
                        $('#progress .bar').css({
                            'background-color' : "#2694E8",
                            'width' : '0%'
                        });
                    }
                data.submit();
                $("#testUploadButton").off("click")
            })
        },

这篇关于如何使用blueimp文件上传插件只上传一次文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆