I have the following code which kind of works but for some reason the $download includes the part inside into the downloaded file.
<form method="post">
<button id="click" name="click">Download</button>
</form>
<?php
if(isset($_POST['click'])){
$files = scandir('/local/path', SCANDIR_SORT_DESCENDING);
$newest_file = $files[0];
$download = $newest_file;
header("Content-Type: text/plain");
header('Content-Disposition: attachment; filename="'.$download.'"');
readfile("/local/path/$download");
}
?>
Downloaded file
form method="post">
<button id="click" name="click">Download</button>
</form>
Start-of-the-actual-log
blabla
blabla
blabla
What is causing this to happen? I only want to download the newest file in a folder.