Grish Grish - 10 months ago 81
Javascript Question

Dropzone.js- How to delete files from server?

I am using dropzone.js.
When I try to delete files only the thumbnails get deleted but not the files from server.
I tried some ways but it just gives me the name of the image which was on client side and not the name on server side(both names are different, storing names in encrypted form).

Any help would be much appreciated..


The way I handle this, is after each file is uploaded and stored on the server, I echo back the name I give the file on my server, and store it in a JS object, something like this:


move_uploaded_file($_FILES['file']['tmp_name'], $newFileName);
echo $newFileName;


dropZone.on("success", function(file, serverFileName) {
  fileList[serverFileName] = {"serverFileName" : serverFileName, "fileName" : };

With this, you can then write a delete script in PHP that takes in the "serverFileName" and does the actual deletion, such as:


    url: "upload/delete_temp_files.php",
    type: "POST",
    data: { "fileList" : JSON.stringify(fileList) }


$fileList = json_decode($_POST['fileList']);

for($i = 0; $i < sizeof($fileList); $i++)