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
Release: 2016-07-13 09:51:23
Original
979 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template