HTTP Headers to Download a File

 
<?php

$file_name = 'example.txt';

header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Transfer-Encoding: binary');

readfile($path_to_file . '/' . $file_name);

?>

 

Related Snippets

•  Set time limit indefinitely
•  Send Email with utf-8 characters on the subject
•  Send Email with Attachment
•  Send Email in Html and Plain Text formats