What are my options when it comes to rendering an image file? Let’s say I have one saved in foo/bar.png
Currently I know I can use readfile() or better yet, X-Sendfile (I’m on Apache). What are some other ways to do it that are better than using readfile()?
I want to output the image to the browser (Content-Type: image/png)
The best solution is to allow your webserver (Apache) to serve the content itself. If PHP must be used instead, all you need to to is ensure that the Content-Type is set to the appropriate value first:
Then use
readfile()to send the image itself.