<?PHP
//forceDownload.php
$file = $_GET['file'];
if(!$file) {die('Error: File was not set.');} //kill if file isn't set
else {
if(!file_exists($file)) {die('Error: File count not be found.');} //kill if file isn't found
else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
readfile($file);
die();
}
}
?>
//test.html
Download Image: <a href="forceDownload.php?file=image.png">Download</a>
<br>
Download Image2: <a href="forceDownload.php?file=image2.png">Download</a>
<br>
Download Song: <a href="forceDownload.php?file=song.mp3">Download</a>