Jump to content

Deleting files with a checkbox


networkthis

Recommended Posts

I am trying to accomplish the following, but am having a hard time figuring out where to go with it.

 

I have a file directory which displays all the files in the directory and displays all relevent info about the file on the page allowing the user to delete the file or save the file.  However I would like to use a checkbox and select multiples to be deleted at the same time.  Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/109072-deleting-files-with-a-checkbox/
Share on other sites

make the checkboxes an array and make the values the file names. Then when the page is submitted iterrate through the array and delete the files in the array.

 

Sample code

 

Form:

file1.jpg <input type="checkbox" name="fileDelete[]" value="file1.jpg"><br>
file2.jpg <input type="checkbox" name="fileDelete[]" value="file2.jpg"><br>
file3.jpg <input type="checkbox" name="fileDelete[]" value="file3.jpg"><br>

 

Processing Page:

<?php

if (count($_POST['fileDelete'])) {

    foreach ($_POST['fileDelete'] as $file) {

        //Delete the file
    }
}

?>

 

Of course you are going to want to implement some good validation else someone might maliciously delete any files on the server by submitting custom forms.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.