Still need help deleting files
Posted: Mon May 31, 2010 6:33 pm
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.
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.
Code: Select all
<?
// 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.
Code: Select all
<?php
$files = $_POST['delete'];
$path = "/upload/$files";
$path = "/upload/$files.*";
if ($file = basename($path));{
echo($file);
}
?>