[PHP] Re: Multiple file delete

2005-03-11 Thread Jason Barnett
Ashley M. Kirchner wrote:

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.

-- A

Have each checkbox that is created have its name set to the name of the
directory.  Then foreach($_POST['checkboxes']) and if the box was
checked, then you delete that directory.  Just be sure to do data
validation on each pass through the loop.

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


[PHP] Re: Multiple file delete

2005-03-11 Thread Jamie Alessio
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.txtfile1.txtbr
input type=checkbox name=file[] value=file2.txtfile2.txtbr
input type=checkbox name=file[] value=file3.txtfile3.txtbr
input type=checkbox name=file[] value=file4.txtfile4.txtbr
--
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