我在我的项目中使用了一个 jQuery 版本。我希望你不介意,也许这无论如何都会有所帮助..?
var dropbox = $(form);
var dropzone_files = [];
dropbox.dropzone({
url: '/etc/',
init: function() {
var Dropzone = this;
// remove function
this.on('removedfile', function(file) {
for(var i=0; i< dropzone_files.length; i++) {
if (file.name == dropzone_files[i]['old_name']) {
var file_name = dropzone_files[i]['new_name'];
var data = { 'file_name' : dropzone_files[i]['new_name'] };
break;
}
}
console.log(data);
var removeData = form.serialize() + '&' + $.param(data);
//console.log(removeData);
$.ajax({
type: 'POST',
url: 'your-dropzone-remove-file.php',
data: removeData,
success: function(report) {
dropzone_files.splice(i,1);
console.log(dropzone_files);
//do more things here
});
// end init
},
//upload function
success: function(file, Response) {
//console.log(Response); is your response from php file of whatever rename.
// pair up old-filename with new file name.
dropzone_files.push({'new_name': Response, 'old_name': file.name});
//console.log(dropzone_files);
// do whatever
}
});
我发现在成功或删除事件中,函数(文件)的“文件”(即 file.name)始终是拖入保管箱的原始文件名。没有办法改变这一点。因此,如果您在上传过程中上传重命名的文件,除非我们将值存储在某处,否则您将无法删除它。
我尝试了很多尝试来扭曲它的值或更新它的值,包括 append()、push() 和 map(),但都没有成功。
所以在upload.php 上,我返回存储在服务器中的新文件名的回显。
然后我在成功事件期间针对 file.name 使用“中等”自定义数组/对象将其配对。
dropzone_files.push({'new_name': Response, 'old_name': file.name});
然后,在删除时,由于 file 仍然是原始文件名,但这一次,我们可以与 arrayobject 进行比较以获取新的文件名,并在每次单击时通过另一个 ajax post 从数组中删除该对象,但这一次, 使用新的文件名,引用。
这也是:https://github.com/enyo/dropzone/issues/656
问候。