You can force download when a user clicks on the download link.
download.php
file on your server
<?php
$fileName = $_GET['filename'];
/* make sure to filter the file so that one could not download any other restricted file. Or better, keep your publicly downloadable files in a folder called "public_files" and store files in that */
$filesFolder = "public_files";
if (file_exists($filesFolder . "/" . $fileName)) {
/* from https://stackoverflow.com/a/3476444/5882307 */
$fileSize = filesize($filesFolder . "/" . $fileName);
// Output headers.
header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: " . $fileSize);
header("Content-Disposition: attachment; filename=" . $fileName);
// Output file.
readfile($filePath);
exit();
} else {
die('The provided file path is not valid.');
}
?>
And then you can link your file as :
<a href="download.php?filename=yourfile.html">Download</a>