PHP mandatory file download function code of arbitrary file format

  • 2020-03-31 20:49:53
  • OfStack

 
 
function force_download($file) 
{ 
if ((isset($file))&&(file_exists($file))) { 
header("Content-length: ".filesize($file)); 
header('Content-Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename="' . $file . '"'); 
readfile("$file"); 
} else { 
echo "No file selected"; 
} 
} 

Here is an excerpt from a previous post on this site. More tips are available.
(link: #)

Related articles: