How to convert image files into binary output in php
This article describes the method of converting image files into binary output in php. Share it with everyone 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;
|
1
2
3
4
|
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.
http://www.bkjia.com/PHPjc/1014278.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1014278.htmlTechArticleHow to convert image files into binary output in php. This article describes how to convert image files into binary output in php. . Share it with everyone for your reference. The specific implementation method is as follows...