PHP header image-type output vs Location redirect to binary in fs PHP header image-type output vs Location redirect to binary in fs curl curl

PHP header image-type output vs Location redirect to binary in fs


I'm against header -> location solution as you will add an extra request to your server. Try this solution instead:

if (file_exists($file)) {        header('Content-Type: image/png');        readfile($file);        exit;    }

This solution should have minimal overhead and memory occupation.