Home >Backend Development >PHP Problem >How to convert php images to binary
How to convert php images into binary: first get the image address; then open it in binary mode through the "fopen($image,'rb');" method; then read the data through the fread function; and finally output the binary Just data.
Recommended: "PHP Video Tutorial"
PHP converts images into binary
Get the image binary data
$image = 'images/psb.jpg'; //图片地址 $fp = fopen($image,'rb'); //以二进制模式打开 $content = fread($fp,filesize($image)); //读取 echo $content; //输出二进制数据,为乱码
The obtained binary data is output as an image (just add header)
header( "Content-type: image/jpeg"); $image = 'images/psb.jpg'; //图片地址 $fp = fopen($image,'rb'); //以二进制模式打开 $content = fread($fp,filesize($image)); //读取 echo $content; //输出图片
The above is the detailed content of How to convert php images to binary. For more information, please follow other related articles on the PHP Chinese website!