Reputation: 1273
When checking several checkboxes, i grab all the values with $_POST["checkboxes_delete"]
Piece of the jquery ajax:
$.ajax({
url:"",
method:"POST",
data:{ checkboxes_delete:checkboxes_delete },
success:function(data){
// and so on
In my php:
if(isset($_POST["checkboxes_delete"])) {
$result = $_POST["checkboxes_delete"];
print_r($result);
unlink($_POST['checkboxes_delete']);
exit;
}
When checking 3 checkboxes per example, print_r
shows me the files, something like below:
uploads/image1.jpg,uploads/image2.jpg,uploads/image3.jpg
How can i unlink them all?
unlink($_POST['checkboxes_delete']);
deletes only 1 file and works only if i check 1 checkbox...
Upvotes: 1
Views: 139
Reputation: 748
You can try this:
if(isset($_POST["checkboxes_delete"])) {
$result = explode(",",$_POST["checkboxes_delete"];
foreach($result as $file){
unlink($file);
}
exit;
}
Upvotes: 3