Home >Backend Development >PHP Tutorial >How to convert image files into binary output in php_PHP tutorial

How to convert image files into binary output in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:51:13918browse

How PHP converts image files into binary output,

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1014432.htmlTechArticleHow to convert image files into binary output in php. This article describes how php converts image files into binary output. method. Share it with everyone for your reference. The specific implementation methods are as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn