Jump to content

How can I force a file to download instead of opening


HGeneAnthony

Recommended Posts

You can use this function

 

function force_download($file)
{
$dir = "";
if ((isset($file))&&(file_exists($dir.$file))) 
{
   header("Content-type: application/force-download");
   header('Content-Disposition: inline; filename="' . $dir.$file . '"');
   header("Content-Transfer-Encoding: Binary");
   header("Content-length: ".filesize($dir.$file));
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename="' . $file . '"');
   readfile("$dir$file");
}
}      

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.