file_get_contents or readfile for displaying filesystem image

前端 未结 5 1186
栀梦
栀梦 2020-12-14 21:29

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

5条回答
  •  天涯浪人
    2020-12-14 22:07

    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().

提交回复
热议问题