まず、file_get_contents()
$image = file_get_contents(__DIR__ . '/sample.jpg');
header('Content-Type: image/jpg');
header('Content-Length: '. count($image));
header('Content-Disposition: attachment; filename=sample.jpg');
echo $image;
続いて、readfile()
$filename = (__DIR__ . '/sample.jpg');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=sample.jpg');
readfile($filename);
いいですねー
まあ、フレームワークによって作法があるようです。