|
This seems to work for me to make downloading of files work the right way (not opening as word document withing the browser window).
<?php
/*
//Example:
streamAttached('/path/to/file.txt','filename.txt');
*/
function streamAttached($path,$name)
{
header('Pragma: private');
header('Cache-control: private, must-revalidate');
header("Content-Type: application/octet-stream");
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.($name).'"');
readfile($path);
exit;
}
?>
Sign up to add your own comment here!
Comments
|
|
| Unless you really want to send the file with a different filename, I'd remove the second variable, and just use htmlentities(basename($path)) for the filename. |
More comments: 1
|
|