JsusSalv Posted January 14, 2008 Share Posted January 14, 2008 Hello: I have gone through the help files and am still in need of help. All I need is to create a simple XHTML form that scans a directory, shows the files (all will be image files), and adds a checkbox that allows users to delete a particular file. Ideally, an "Are you sure you want to delete this file" message should appear/popup followed by a file deletion confirmation. Below is my code for the form: <?php $webAddr = "http://www.xxxx.xxx/xx"; $dir = "/path/to/directory/where/the/Images/are/located/"; if(($dirfiles = scandir($dir))!==false) { foreach($dirfiles as $imgfile) { if($imgfile != '.' && $imgfile != '..') echo "<img src=\"$webAddr/Images/$imgfile\" title=\"$imgfile\" alt=\"$imgfile\" />"; if (isset($_POST['delete']) && $_POST['delete']=='yes') { print 'Image is being deleted...'; exit; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="form1" id="form1" method="post" action="delete_image_file.php"> <input type="hidden" name="delete" value="yes" /> <p> <input name="checkbox[<?php echo $imgfile; ?>]" type="checkbox" id="checkbox[<?php echo $imgfile; ?>]" value="checkbox" /> <?php echo $imgfile; ?></p> <input type="submit" value="Delete Image"> </form> </body> </html> For the file, delete_image_file.php, that should process the form: <?php $dir = "/path/to/directory/where/the/Images/are/located/"; if(($dirfiles = scandir($dir))!==false) { foreach($dirfiles as $imgfile) { if($imgfile != '.' && $imgfile != '..') if (unlink('/path/to/directory/where/the/Images/are/located/' . $imgfile)) { print "The file $imgfile has been deleted!\n"; } else { print "Deletion of $imgfile failed!\n"; } } } ?> I am having much difficulty figuring out what goes where. Anyhow, if you have some info you'd like to share then please add example scripts. I don't need posts that tell me what I should or shouldn't do. That isn't productive for me. Thank you everyone! Link to comment https://forums.phpfreaks.com/topic/85939-unlink-form-help/ Share on other sites More sharing options...
tibberous Posted January 14, 2008 Share Posted January 14, 2008 To do the alert box: <input type="submit" value="Delete Image" onclick="return confirm('Are you sure you want to delete this file?')"> I'm to tired for anything but that. Link to comment https://forums.phpfreaks.com/topic/85939-unlink-form-help/#findComment-438788 Share on other sites More sharing options...
JsusSalv Posted January 14, 2008 Author Share Posted January 14, 2008 Refresh yourself my friend Well, what I need is to understand where the processing part of the code gets put into so that files do get deleted. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/85939-unlink-form-help/#findComment-439096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.