Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get image from URL to byte array and reverse

Tags:

android

php

http://oep.esy.es/testimage.php as you can see here, that is the output of png image. image is here:

http://oep.esy.es/images/object/1365-50.png

My code is that:

$homepage = file_get_contents("http://oep.esy.es/images/object/1365-50.png");
echo $homepage;

I want to store as byte array because in Android client, I need that image so I need to pull it. Is it bad method?

But when I try to show image, it doesnot show:

echo "<img src='data:image/png;base64, $homepage' />";

I also tried jpeg but did not work.


1 Answers

You're missing the base64_encode() function, something like:

$path = file_get_contents("http://oep.esy.es/images/object/1365-50.png");
echo "<img src='data:image/png;base64, " . base64_encode($path) ."'/>";
like image 191
Pedro Lobito Avatar answered Dec 08 '25 20:12

Pedro Lobito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!