Paritosh Mahale
Paritosh Mahale

Reputation: 1316

Dropzone configure for delete option

I have added below code of dropzone

<html>

<head>   

<!-- 1 -->
<link href="dropzone.css" type="text/css" rel="stylesheet" />

<!-- 2 -->
<script src="dropzone.js"></script>>

</head>

<body>

<!-- 3 -->
<form action="upload.php" class="dropzone"></form>

</body>

</html>

And it works fine. But I am wondering how do I add delete button for deleting particular file from server.

Upvotes: 0

Views: 353

Answers (1)

William-H-M
William-H-M

Reputation: 1054

First you must add to dropzone configuration the option addRemoveLinks: true

Then we listen to event for when a file is removed and the do an Ajax call to delete it from server (in here I just send the file name) and on in there just do the codebehind deleting a file.

  Dropzone.autoDiscover = false;

  myDropzone = new Dropzone("#DzUpload", {
                    url: 'upload.php',                       
                    addRemoveLinks: true, //This will show remove button                     
                });
  //Init Dropzone
  myDropzone.on("removedfile", function (file) {
                if (!file.name) { return; } // The file hasn't been uploaded
                $.ajax({
                    type: 'POST',
                    url: 'delete.php',
                    dataType: "json",
                    data: { FileName: file.name },
                    success: function (result) {                            
                       console.log("deleted")
                    }
                });
            });

Upvotes: 1

Related Questions