Display image outside public folder with file_get_contents function

Hello,

I’m currently creating a website where users can upload their images and create a photo gallery.
I’m storing the images outside the public directory and I’m using “echo file_get_contents” to display these images.
My question is: will fetching the images through the function file_get_contents be significantly slower than
displaying the images when they are in the public folder using normal “img src” method?

Slightly. The answer rather depends on how big the files are. Essentially, using the get_contents is a double load - the server has to read the data entirely (to complete the file_get_contents), and then echo it out.

That said, unless you’re heavily loading your server, or using multi-megabyte images, the difference will be negligable.