PHP

HOW TO FORCE FILE DOWNLOAD IN PHP

HTTP HEADERS header("Content-Type: application/octet-stream"); header("Content-Type: Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"IMG.JPG\"");

PHP FORCE DOWNLOAD

01

OUTPUT FILE readfile("IMG.JPG");

DUMMY DATA $users = [   ["Jon Doe", "jon@doe.com"],   ["Jan Doe", "jan@doe.com"],   ["Jun Doe", "jun@doe.com"] ];

GENERATE & DOWNLOAD (A)

02

GENERATE & DOWNLOAD (B)

03

HTTP HEADERS header("Content-Type: application/octet-stream"); header("Content-Type: Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"usr.csv\"");

OUTPUT DATA foreach ($users as $u) { echo implode(",", $u) . "\r\n"; }