Dropzone.js 删除从服务器预加载的文件

时间:2021-02-10 21:02:40

标签: javascript server dropzone.js delete-file preload

我尝试为我的文件实现 dropzone:

这是我的代码,使用 php 我从服务器插入所有图像:

 var foto_upload= new Dropzone("#documenti_personali",{
url: "<?=base_url().'/user_Isee/dropzone_documenti_personali' ?>",
maxFilesize: 2,
method:"post",
acceptedFiles:"image/*",
paramName:"userfile",
dictInvalidFileType:"Tipo file non permesso",
dictRemoveFile : "Rimuovi file",
addRemoveLinks:true,
init: function () {
let myDropzone = this;

// If you only have access to the original image sizes on your server,
// and want to resize them in the browser:
<?php 
    $n=0;
    foreach ($lista_documenti_dichiarante as $v) :
?>  
let mockFile<?=$n;?> = { name: "<?= $v->nome_file_originale ?>", size: 12345 };
myDropzone.displayExistingFile(mockFile<?=$n;?>, "<?=base_url() ?>/uploaded/xyz_xrh/documenti_personali_isee/1/<?= $v->nome_file ?>");



<?php
    $n++;
    endforeach; 
?>

}
 });

这是添加其他参数保存到db并删除它(token)

 foto_upload.on('sending', function(file, xhr, formData){
var timeStampInMs = window.performance && window.performance.now && window.performance.timing && window.performance.timing.navigationStart ? window.performance.now() + window.performance.timing.navigationStart : Date.now();

file.token=timeStampInMs+'_'+Math.random();
formData.append('id_isee', '<?=$record->id?>');
formData.append('token_file', file.token);

 });

这个要删除:

 foto_upload.on("removedfile",function(file){
var token=file.token;
$.ajax({
    type:"post",
    data:{token_file:token},
    url:"<?=base_url().'/user_Isee/dropzone_remove_documenti_personali' ?>",
    cache:false,
    dataType: 'json',
    success: function(){
        console.log("remove poto success");
    },
    error: function(){
        console.log("Error");

    }
});

});

我将令牌存储在我的数据库中,但如何将令牌关联到从服务器预加载的文件以删除它?

o.t.有一种方法可以设置: 'span class="dz-upload" data-dz-uploadprogress="" style="width: 100%;">

关于从服务器预加载的文件?

0 个答案:

没有答案