Force file Download
Monday, May 6th, 2013 - 11:52 AM - Coding
Provide files to the user by forcing them to download.
<?php /*************************************** *@file - physical path to file on server *@$filename4User - New file which will * use as new name for downloaded file ****************************************/ function force_download($file, $filename4User) { if ((isset($file))&&(file_exists($file))) { header("Content-length: ".filesize($file)); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename4User. '"'); readfile("$file"); } else { echo "No file selected"; } } ?>