« Return to all random blog posts
PHP Force a File to Download
Here's how to force the browser to download a file:
<?php
$file = "/path/to/foo.jpg";
$filename = basename($file);
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$filename.'";');
readfile($file);
exit;
?>



Comments:
Show comments