file_get_contents or readfile for displaying filesystem image

前端 未结 5 1188
栀梦
栀梦 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:19

    I would do something like:

    header('Content-type: image/jpeg');
    readfile('something.jpg');
    

    readfile() seems more useful for this purpose as it reads a file and writes it to the output buffer returning the number of bytes read from the file, or false on an error.

提交回复
热议问题