Hi Guys,
I am new to this place and wonder if anyone here could help. I have been working on a script that supposed to scan the contents of a folder and then display the results into a drop down box. I then then want to be able select the file a file and then delete it via delete button. This is where I am up to but it will just not delete the file. I just keep on getting undefined index on line 6 of delete.php
<h4>Delete existing File</h4>
<form method="post" action="deleted.php">
<p><select name="id"></p>
<option value="">-- Choose a partner --</option>
<?php
echo "<form>";
//Looks into the directory and returns the files, no subdirectories
echo "<select name='yourfiles'>";
//The path to the file directory
$file = $_POST['yourfiles'];
$dirpath = "uploads";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
if (!is_dir("$dirpath/$file")) {
//Truncate the file extension and capitalize the first letter
echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\\..*$/', '', $file))) . '</option>';}
}
echo "</select></p>";
echo '<p><input type="submit" value="Delete" class="submit" /></p>';
echo "</form>";
closedir($dh);
?
delete.php
<?php
ini_set('display_errors',1);
$dirpath = "uploads";
$file_to_delete = $_POST['yourfiles'];
if ( unlink ($dirpath .'/'. $file_to_delete) ) {
echo $file_to_delete . " deleted.";
}
else {
echo "Error.";
}
?>
Any help on this would be appreciated.