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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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