【问题标题】:Dropzone.js remove button with phpDropzone.js 用 php 删除按钮
【发布时间】:2013-06-28 08:06:45
【问题描述】:

我使用 dropzone.js 来制作一个不错的上传表单。 我链接了 php 代码来上传文件,并设置了 addRemoveLinks=true 所以我有删除按钮。

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

php 做起来很简单,但我不需要知道如何关联它们。 我已经尝试在此函数中使用 $.post 删除文件:函数(文件)但没有成功。

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

},

【问题讨论】:

    标签: php jquery drag-and-drop dropzone.js


    【解决方案1】:

    首先,您不应该简单地覆盖默认的removedfile 事件处理程序,而应该将您自己的处理程序连同它一起注册。

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

    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 回调中,文件处理程序仍然是没有其他数据的原始处理程序?
    • 我正在尝试使用上述技术首先显示然后删除已经上传到服务器上的文件,但成功事件没有触发。请帮忙
    猜你喜欢
    • 1970-01-01
    • 2012-12-09
    • 2014-01-30
    • 1970-01-01
    • 2013-12-24
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    相关资源
    最近更新 更多