This is one of many functions that I've tried to use to download files from a webpage. The folder is 'files' and I get the file name in the first IF clause, and store the location of it in the 'path' variable. The rest I've copied from online sources, which has positive reviews. I've tried many like this, but they all crash the page.
if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
$filename = $_GET['file'];
$path = 'files/' . $filename;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
flush();
readfile($path);
exit;
}
<div id="downloadWrapper" class="downloadWrapper">
<h1>Download the Mind Booster App</h1>
<hr/>
<div class="container" style="max-width:780px;">
<div class="col-md-4">
<a href="mindbooster.php?file=mindBooster.exe" name="mindBooster"><img src="images/downloadWindows.png" alt="windows"></a>
</div>
<div class="col-md-4">
<a href=""><img id="androidButton" src="images/play.png" alt="android"></a>
</div>
<div class="col-md-4">
<a href=""><img id="appleButton" src="images/downloadApple.png" alt="apple"></a>
</div>
</div>
</div>