Can anyone advise on what is the best PHP function for displaying an image stored in a filesystem - file_get_contents
or readfile
. We are switching
file_get_contents()
is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance. But that aside, I don't know what is better. You could try to see if a huge file give better performance with file_get_contents()
, but I expect the network traffic is a much bigger concern than the servers file-IO. and readfile()
is used to download the file by passing the content-type
in header()
.