Force Download PHP

Posted by engineerisaac


Posted on 7 months ago

http://php.net/manual/en/images/e88cefb5c3fca5060e2490b9763c4433-readfile.png






$file = 'monkey.gif';



if (file_exists($file)) {

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename="'.basename($file).'"');

header('Expires: 0');

header('Cache-Control: must-revalidate');

header('Pragma: public');

header('Content-Length: ' . filesize($file));

readfile($file);

exit;

}







Comments are For the Community.

If you would like to Comment, Consider joining the Community!

We believe in accountability. Your comments are connected to your profile.

Register Login


Other Engineerisaac Articles