1

I am using dropzone for file upload. I want to delete the files on the server when the removeLink is clicked. For that I use Ajax which opens the .php site. But somehow I can't pass the filename of the file which should be deleted (the delete_image.php works). How can I pass the filename so it can be deleted?

 addRemoveLinks: true,
 removedfile: function(file) {
$.ajax({
type: 'POST',
url: 'delete_image.php',
data: {name: +file, dir: "<? echo $_GET['id']; ?>"},
});
 var _ref;
 return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) :       void 0;        
  }

Credit: code from this site

Community
  • 1
  • 1
Deproblemify
  • 3,340
  • 5
  • 26
  • 41

1 Answers1

2

Most simple way

JS file,this script will run when you click delete button

this.on("removedfile", function(file) {
alert(file.name);

$.ajax({
url: "uploads/delete.php",
type: "POST",
data: { 'name': file.name}
});


});

php file "delete.php"

<?php
$t= $_POST['name'];
echo $t;
unlink($t); 
?>
yogesh singh
  • 605
  • 6
  • 9