Welcome Guest, Not a member yet? Register   Sign In
Force to download file
#1

Hi
I need to force download any for for download
Actually i dont want to play audio or show picture in browser and user have to download it
Reply
#2

Force Download:

PHP Code:
$file "filename.ext";

// Quick check to verify that the file exists
if( !file_exists($file) ) die("File not found");

// Force the download
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Pragma: private');
header("Content-Disposition: attachment; filename="" . basename($file) . """);
header("Content-Length: " filesize($file));
header("Content-Type: application/octet-stream;");

readfile($file); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(02-15-2018, 10:49 AM)InsiteFX Wrote: Force Download:

PHP Code:
$file "filename.ext";

// Quick check to verify that the file exists
if( !file_exists($file) ) die("File not found");

// Force the download
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Pragma: private');
header("Content-Disposition: attachment; filename="" . basename($file) . """);
header("Content-Length: " filesize($file));
header("Content-Type: application/octet-stream;");

readfile($file); 

Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB