Force browser to download a file
When you want users to download a file but the browser is displaying it instead (it happens with images, plain text, pdfs, ...), you can use this kind of code.
$downloadableFilename = 'toto.txt';
$realFilePath = '/tmp/tata.txt';
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $downloadableFilename . '"');
header('Content-Transfert-Encoding: binary');
readfile($realFilePath);
Language: PHP | User: haltabush | Created: Oct 3, 2013