我想在文件上传后更新图像名称,并且在成功时我必须在dropzone字段中更改图像名称。怎么做。我正在使用http://dropzone.js。我已尝试使用以下代码,但我不确定如何将文件上传并将响应名称添加到drozpone字段后附加图像名称
var fileList = new Array;
var i =0;
Dropzone.options.myAwesomeDropzone = {
addRemoveLinks: true ,
maxFiles: 5,
acceptedFiles: 'image/*',
url: "<?php echo site_url('settings_pro/work_picture_upload'); ?>",
init: function() {
thisDropzone = this;
this.on("maxfilesexceeded", function(file){
alert("No more files please!");
this.removeFile(file);
this.addFile(file);
});
this.on('removedfile', function(file) {
console.log(file);
var file_name = file.name;
$.ajax({
type: 'POST',
url: '<?php echo base_url('settings_pro/delete_image'); ?>',
data: { 'filename': file_name },
success: function(report) {
console.log(report);
},
error: function(report) {
console.log(report);
}
});
});
$.get('<?php echo base_url('settings_pro/get_picture'); ?>', function(data) {
$.each(data, function(key,value){
//alert(data);
//var mockFile = { name: value.name, size: value.size };
var mockFile = { name: value.name};
thisDropzone.options.addedfile.call(thisDropzone, mockFile);
thisDropzone.options.thumbnail.call(thisDropzone, mockFile,
value.path);
});
});
this.on("successmultiple", function(files, response) {
alert("hi");
// event when files are successfully uploaded
// you can return a response string and process it here through 'response'
});
this.on("success", function(file, response) {
// fileList[serverFileName] = {"serverFileName" : response.name, "fileName" : file.name };
file.serverId = response;
//$('#dz-preview').html('<img src="" width="200" height="200" alt="<?php //echo $empNameFull; ?>">');
// location.reload();
});
this.on('complete', function () {});
}
}