Dropzone删除上传的图像数据库和服务器

时间:2018-05-14 15:49:00

标签: javascript ajax file dropzone.js dropzone

我正在使用dropzone。现在拖动图像成功保存。

点击后删除它会删除我们所期望的文件。

但是当页面加载时,以前的文件正在显示并单击删除。它不会删除该文件。我不知道为什么?我应该添加什么?还是删除?或改变?

这些是我的代码:

var total_photos_counter = 0;
    var dropZone = new Dropzone('#my-dropzone',{
    uploadMultiple: true,
    parallelUploads: 2,
    maxFilesize: 4,
    addRemoveLinks: true,
    dictRemoveFile: 'Remove',
    dictFileTooBig: 'Limit: 4MB',
    timeout: 10000,
    init: function () {
        this.on("removedfile", function (file) {
            $.post({
                url: '/images-delete',
                data: {id: file.name, _token: $('[name="_token"]').val()},
                dataType: 'json',
                success: function (data) {
                    total_photos_counter--;
                    $("#counter").text("# " + total_photos_counter);
                }
            });
        });
    },
    success: function (file, done) {
        total_photos_counter++;
        $("#counter").text("# " + total_photos_counter);
    }
});



for (i = 0; i < existingFiles.length; i++) {
    dropZone.emit("addedfile", existingFiles[i]);
    dropZone.emit("thumbnail", existingFiles[i], existingFiles[i].url);
    dropZone.emit("complete", existingFiles[i]);
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

你应该删除

`for (i = 0; i < existingFiles.length; i++) {
    dropZone.emit("addedfile", existingFiles[i]);
    dropZone.emit("thumbnail", existingFiles[i], existingFiles[i].url);
    dropZone.emit("complete", existingFiles[i]);
}`

因为此代码在页面加载两次时运行