Dropzone.js使用php删除按钮

Dropzone.js使用php删除按钮,php,jquery,drag-and-drop,dropzone.js,Php,Jquery,Drag And Drop,Dropzone.js,我使用dropzone.js创建了一个很好的上传表单。 我链接了php代码来上传文件,并设置了addRemoveLinks=true,因此我有了remove按钮 我需要一个想法,如何有效地删除与php代码上传的文件时,我点击删除按钮 php很简单,但我不需要知道如何关联它们。 我已经尝试在这个函数removedfile:function(file)中使用$.post,但没有成功 removedfile: function(file) { $.post("test.php");

我使用dropzone.js创建了一个很好的上传表单。 我链接了php代码来上传文件,并设置了addRemoveLinks=true,因此我有了remove按钮

我需要一个想法,如何有效地删除与php代码上传的文件时,我点击删除按钮

php很简单,但我不需要知道如何关联它们。 我已经尝试在这个函数removedfile:function(file)中使用$.post,但没有成功

  removedfile: function(file) {
    $.post("test.php");
    var _ref;
    return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;

},

首先,您不应该简单地覆盖默认的
removedfile
事件处理程序,而应该注册自己的处理程序

您需要首先从服务器获取ID(这样您就知道如何关联它),然后使用它来设置delete调用

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
    });
  }

“文件”不是只读的吗?我也试过了,但在removefile回调中,文件处理程序仍然是原始的,没有其他数据?我尝试使用上述技术先显示,然后删除服务器上已上载的文件,但on success事件没有触发。请帮忙