Thursday, December 17, 2015

Make Download link and force to download on browser using PHP

$name  = $_GET['name'];
$fname = $_GET['file_name'];

$dir_path  = __DIR__.'/../uploads/';

header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"" . $name . "\";");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($dir_path.$fname));
ob_clean();
flush();

readfile($dir_path.$fname);
exit;

No comments:

Post a Comment