gpt4 book ai didi

javascript - dropzonejs 一次手动删除服务器上的一个文件

转载 作者:行者123 更新时间:2023-11-29 19:06:03 25 4
gpt4 key购买 nike

我正在使用 dropzonejs 上传和删除服务器上的多个图像。上传多张图片工作正常但一次删除一张图片给我带来了问题。单击删除链接时,所有与图像关联的 ajax 函数都会同时触发,这会导致删除所有文件而不是选定的文件。如何从每个关联的图像文件中区分删除链接???

jQuery(function () {
var articleID = jQuery('#articleID').val();
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone('#media-uploader', {
url: "url?action=kl_upload_article_images",
acceptedFiles: 'image/*',
maxFilesize: 50,
previewTemplate: $('#preview-template').html(),
thumbnailHeight: 120,
thumbnailWidth: 120,
parallelUploads: 100,
uploadMultiple: true,
autoProcessQueue: false,
addRemoveLinks: true,
autoProcessQueue: false,
init: function ()
{
dropZoneObject = this;
//getting file name and directory to preview stored images in dropzonejs
$.get("url?action=kl_edit_article_images&article_id=" + articleID, function (data)
{
//loopging through each data to preview images
$.each(data, function (key, value)
{
var mockFile = {name: value.name, size: value.size};
dropZoneObject.emit("addedfile", mockFile);
var fileUrl = 'fileDirectory/'; ? > '+value.name;
dropZoneObject.emit("thumbnail", mockFile, fileUrl);
dropZoneObject.emit("complete", mockFile);
//@start of removing file
dropZoneObject.on("removedfile", function (file)
{
$.post("url?action=kl_delete_article_images&image_name=" + value.name + "&article_id=" + articleID);
});
//@end of removing file
});
dropZoneObject.on('sending', function (file, xhr, formData)
{
formData.append('articleId', articleID);
});
});
}
});
});

最佳答案

好吧,由于这些问题,我已经想出了从服务器删除文件的方法 link1 link2 .我已经发布了我的代码的最终结果。希望它能帮助别人。

jQuery( function() {
var articleID = jQuery('#articleID').val();
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone('#media-uploader', {
url: "url?action=kl_upload_article_images",
acceptedFiles: 'image/*',
maxFilesize : 50,
previewTemplate: $('#preview-template').html(),
thumbnailHeight: 120,
thumbnailWidth: 120,
parallelUploads: 100,
uploadMultiple: true,
autoProcessQueue: false,
addRemoveLinks : true,
autoProcessQueue : false,
//removedfile is called whenever file is removed from the list
removedfile : function(file)
{
var imageName = file.name;
var confirmation = confirm('Are you sure you want to delete this image?');
if(confirmation == true)
{
//post request to remove file from server
$.post("url?action=kl_delete_article_images&image_name=" + imageName +"&article_id="+ articleID);
//deleting thumbnails
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
}
},
init: function()
{
dropZoneObject = this;
//getting file name and directory to preview stored images in dropzonejs
$.get("url?action=kl_edit_article_images&article_id=" + articleID,function(data)
{
//looping through each data to preview images
$.each(data,function(key,value)
{
var mockFile = {name:value.name,size:value.size};
dropZoneObject.emit("addedfile", mockFile);
var fileUrl = 'fileDirectory/';?>'+value.name;
dropZoneObject.emit("thumbnail", mockFile, fileUrl);
dropZoneObject.emit("complete", mockFile);
});
//end of loop

dropZoneObject.on('sending', function(file, xhr, formData)
{
formData.append('articleId', articleID);
});
});
}
});

关于javascript - dropzonejs 一次手动删除服务器上的一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com