May 25, 200917 yr I have a basic php delete from directory script but it will not let me delete images: delete1.php - This allows the user to select the directory they want to delete from: <form method="POST" action="delete2.php" enctype="multipart/form-data"> <label>Select a School that you would like to delete images from: <select name="list" id="list"> <option value="albert/thumbs">Albert Village</option> <option value="ashby_hilltop/thumbs">Ashby Hilltop</option> <option value="ashby_school/thumbs">Ashby School</option> <option value="ashby_willesley/thumbs">Ashby Willesley</option> <option value="ashbycofe/thumbs">Ashby C of E</option> <option value="blackfordby/thumbs">Blackfordby</option> <option value="donisthorpe/thumbs">Donisthorpe</option> <option value="griffydam/thumbs">Griffydam</option> <option value="ivanhoe/thumbs">Ivanhoe</option> <option value="moira/thumbs">Moira</option> <option value="newbold/thumbs">Newbold</option> <option value="oakthorpe/thumbs">Oakthorpe</option> <option value="packington/thumbs">Packington</option> <option value="viscount/thumbs">Viscount Beaumont</option> <option value="woodcote/thumbs">Woodcote</option> <option value="worthington/thumbs">Worthington</option> </select></label><br /><br /> <input type="submit" value="Open Directory" /> </form> delete2.php <?php $path = "$list"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlink($path . "/" . $file) or die("Failed to delete file"); } } ?> <form name="form1" method="post"> <?php $path = "$list"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<img src='$file' alt='$file'><br />"; } closedir($dir_handle); ?> <input type="submit" name="Delete" value="Delete"> </form> Any help would be much appreciated! Cheers!
May 26, 200917 yr A bit more information would probably be helpful. Does it allow you to "open directory" and list the relevant files. How far does the script go before it stops working? This will narrow down the search for errors in your script. I have already noticed a few things that may be causing you problems for example the initial declaration of $path in delete2.php. It should be $path = $_POST['list'] as you are accessing a POST variable from the previous form. Dan
Create an account or sign in to comment