I have a directory on my server, I want to list all the files in it with checkboxes and either delete or download them after choosing.
So far I can list and delete fine using this form, ticking checkboxes and pressing the button. But I also sometimes need to download files to my local machine. Either by ticking the checkbox or right-clicking the file name and downloading with 'save file as' in Chrome browser. But I can't get it working.
How can I download these files?
My page is called download-ui.php
<?php
if(isset($_POST['Submit']))
{
}
foreach ($_POST['select'] as $file) {
if(file_exists($file)) {
unlink($file);
}
elseif(is_dir($file)) {
rmdir($file);
}
}
$files = array();
$dir = opendir('.');
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..") and ($file != "download-ui.php") and ($file != "error_log")) {
$files[] = $file;
}
}
natcasesort($files);
?>
<form id="delete" action="" method="POST">
<?php
echo '<table><tr>';
for($i=0; $i<count($files); $i++) {
if ($i%5 == 0) {
echo '</tr>';
echo '<tr>';
}
echo '<td style="width:180px">
<div class="select-all-col"><input name="select[]" type="checkbox" class="select" value="'.$files[$i].'"/>
<a href="download-ui.php?name='.$foldername."/".$files[$i].'" style="cursor: pointer;">'.$files[$i].'</a></div>
<br />
</td>';
}
echo '</table>';
?>
</table>
<br>
<button type="submit" form="delete" value="Submit">Delete File/s</button>
</form><br>