Dropzone.js remove button with php

后端 未结 1 815
遇见更好的自我
遇见更好的自我 2021-01-14 03:31

I use dropzone.js for a nice upload form. I linked the php code to upload the files and i setted addRemoveLinks=true so i have the remove button.

I need an idea how

1条回答
  •  暖寄归人
    2021-01-14 04:04

    First off, you shouldn't simply overwrite the default removedfile event handler, but rather register your own handler along with it.

    You need to first get the ID back from the server (so you know how to relate to it) and then use this to setup the delete call.

    Dropzone.options.myDropzone = {
      init: function() {
        this.on("success", function(file, response) {
          file.serverId = response; // If you just return the ID when storing the file
          // You can also return a JSON object then the line would
          // look something like this:
          //
          // file.serverId = response.id;
          //
          // In that case make sure that you respond with the mime type
          // application/json
        });
        this.on("removedfile", function(file) {
          if (!file.serverId) { return; } // The file hasn't been uploaded
          $.post("delete-file.php?id=" + file.serverId); // Send the file id along
        });
      }
    

    0 讨论(0)
提交回复
热议问题