mercredi 20 février 2019

how to delete an array of files in php

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




Aucun commentaire:

Enregistrer un commentaire