PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to delete files that have been uploaded to the server. Folder name is upload. Here is the first script which displays the filenames in the folder. This works correctly.
<?
// Define the full path to your folder from root
$path = "/../upload/";
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" || $file == "upload.php" || $file == "index2.php")
continue;
echo "<a href=\"$file\">$file</a><input type=\"checkbox\" name=\"delete[]\" value=\"$file\" /><br />";
}
closedir($dir_handle);
?>
<h5>Delete file from upload directory</h5>
<form action="delete2.php" method="POST"> <input type="submit" value="Delete" /> </form>
Here is the script to delete the files but I've changed it to echo the files to see if they are being passed from the form and It just echoes .* and if I remove that line of code it echoes the directory name which is upload.
Got it. The problem was I was ending the script before the actual code for the form was running. I was using echo to display the checkbox and after I ended the script is where I had the actual form code. Backwards sort of. Simple! Thanks to everyone!