You are here: Re: Multiple file delete « PHP « IT news, forums, messages
Re: Multiple file delete

Posted by Jamie Alessio on 10/19/21 11:10

> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация