Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  173] [ 5]  / answers: 1 / hits: 54433  / 11 Years ago, wed, july 3, 2013, 12:00:00

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..


More From » jquery

 Answers
70

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:



PHP:



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


JS:



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


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



JS:



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


PHP:



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

for($i = 0; $i < sizeof($fileList); $i++)
{
unlink(basename($fileList[$i]));
}

[#77217] Tuesday, July 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
danae

Total Points: 26
Total Questions: 97
Total Answers: 112

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;