I have a page that displays the contents of a folder. Right now, each file has a little 'delete' button next to it that users can click on, however with many files it gets cumbersome. I need to be able to have them click on checkboxes and then hit one delete button which will then get rid of everything checked, but I don't know how to combine the form with PHP so that it takes the info from one into the other and delete what's needed. Any pointers would be very helpful. Thanks.

Ashley,
Try something like this:

To the browser:
--------------
<input type="checkbox" name="file[]" value="file1.txt">file1.txt<br>
<input type="checkbox" name="file[]" value="file2.txt">file2.txt<br>
<input type="checkbox" name="file[]" value="file3.txt">file3.txt<br>
<input type="checkbox" name="file[]" value="file4.txt">file4.txt<br>
--------------

The PHP to process the form:
--------------
foreach($_REQUEST['file'] as $key => $file) {
  // Do your file deletion here using $file
}
--------------

This will allow the user to check all the files they want deleted. When they submit the form to your PHP script there will be an array containing one element for each checkbox they clicked. You can then loop through this and delete the appropriate files.

Be careful when you are allowing the web server to delete files though! Someone could easily POST bogus file names and the web server process will happily delete them if it has the permission. So, be sure to really check the user input and restrict the delete operations to a specific directory.

- Jamie

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to