A function that forces a file to download.
This function will force a file to be downloaded. It accepts $_path as a parameter.
Copy this code and paste it in your HTML
function file_force_dl($_path) {
$mime = 'application/force-download';
header('Pragma: public');
// required header('Expires: 0');
// no cache header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($_path).'"');
header('Content-Transfer-Encoding: binary');
}
Report this snippet