I am currently working on a Directory Browser using PHP and I've stumbled upon a roadblock. I would like to be able to have a user select files using checkboxes, then delete them when they click a button, however I'm not sure how to go about this due to being new to PHP and web development in general. Here is my code so far for the user interface:
<a href="#" onClick="rec('deletestuff')">
<span title="Delete Selected" class="fa fa-trash fa-lg"></span>
<!--Delete Selected-->
</a>
</li>
</ul>
<script type="text/javascript">
function rec(deletestuff) {
$('#newCode').load('delete_selected.php' deletestuff);
}
</script>
<span class="selected col-md-2 col-sm-2 col-xs-1 text-right">
<form method="get">
<input type="checkbox" name="selected[]" value="'.$file.'">
</form>
</span>
then in a seperate PHP file I wrote this algorithm to handle the delete functionality
<?php
foreach($_POST['selected[]'] as $file) {
if(file_exists($lister->getDirectoryPath() . $file)) {
unlink($lister->getDirectoryPath() . $file);
echo "<script type='text/javascript'>alert('Files deleted
successfully.');</script>";
}
elseif(is_dir($file)) {
rmdir($file);
echo "<script type='text/javascript'>alert('Files deleted successfully.');</script>";
}
}
?>
I am pretty sure that I am not performing the handling between the several different types of scripts correctly (specifically having the javascript send its information to the php), however I need some pointers as to where exactly I am failing at this in order to correct it. If needed, I can share more of my source code as it is based on the PHP DirectoryLister found here: https://github.com/DirectoryLister/DirectoryLister
Thanks!