The example in this article describes how PHP converts image files into binary output. Share it with everyone for your reference. The specific implementation method is as follows:
header( "Content-type: image/jpeg"); $PSize = filesize('1.jpg'); $picturedata = fread(fopen('1.jpg', "r"), $PSize); echo $picturedata;
With just 4 lines of code, the image is output to the client in the form of a binary stream, which is no different from opening a picture.
It should be noted here that the header sent depends on the specific situation and may not always be image/jpeg. JPG is image/jpeg, but PNG is image/png. Different types of pictures output different headers.
I hope this article will be helpful to everyone’s PHP programming design.