Php converts an image file to a binary output. Php converts an image file to a binary output. This document describes how php converts an image file to a binary output. Share it with you for your reference. The specific implementation method is as follows: php converts an image file to a binary output method
This example describes how php converts an image file to a binary output. Share it with you for your reference. The specific implementation method is as follows:
|
1
2
3
4 |
Header ("Content-type: image/jpeg ");
$ PSize = filesize('1.jpg ');
$ Picturedata = fread(fopen('1.jpg ', "r"), $ PSize );
Echo $ picturedata;
|
With this simple 4-line code, the image is output to the client in the form of a binary stream, which is no different from opening an image.
Note that the sent header depends on the actual situation, not necessarily image/jpeg. JPG is image/jpeg, but PNG is image/png. different types of images output different headers.
Examples in this article describes how php converts an image file to a binary output. Share it with you for your reference. The specific implementation method is as follows...