I have a dropdown list populated with files pulled from a directory using the PHP listed below that then gets displayed onto a form and am trying to figure out how I can delete them using a delete button in the form when they're selected and displayed.
<input type="hidden" name="Action" value="EDIT" /><input type="hidden" name="Selection" id="Selection" value="-1"><div>Below is the list of your saved codes. To edit your codes, select it from the list.</div>
<select size="1" name="CodeList" id="CodeList">
<?php
$directory = $directory = 'users/' . $_SESSION['username'];
$filesContents = Array();
$files = scandir( $directory ) ;
foreach( $files as $file )
{
if ( ! is_dir( $file ) )
{
$filesContents[$file] = file_get_contents($directory , $file);
echo "<option>" . $file . "</option>";
}
}
?>
</select>
Below is the coding I was staring to use and the error beneath it that I received.
<?php
$dirpath = $directory = 'users/' . $_SESSION['username'];
$file_to_delete = $_GET['$file'];
if ( unlink ($dirpath.'/'.$file_to_delete) ) {
echo $file_to_delete . " deleted.";
} else {
echo "Error.";
}
?>
EDIT for Testing Attempting to use this php it returned the error:
Warning: unlink(users//) [function.unlink]: Is a directory in /home/revo/public_html/evo/avdeleteprocess.php on line 4
Error.
So it appears it found the users folder however it didn't find the file that was pulled from the dropdown.