Hi,

I am a newbie in php and I was wondering if anybody has a clue about the following.

I have an image and I am using base64_encode


$img="test.png";

$fd = fopen (, 'rb');
$size=filesize ($img);
$cont = fread ($fd, $size);
fclose ($fd);
$encimg = base64_encode($cont);

Then I want to decode the string "$encimg" in order to recreate the original image and save it as "test1.png".

Thanks in advance!

    Have you tried [man]base64_decode[/man]?

      Yes, I have tried "base64_decode" but I can't make it work.

      I can't understand what I don't do right 😕 , so I would be grateful if you could just provide me some code that implements the decoding and recreation of the original image.

      Thanks!

        And then what would you do if what I write is exactly what you attempted (which I haven't seen)?

        $image = base64_decode($encimg);
        file_put_contents('decoded.png', $image);
        

          It's working!

          Thanks!

          As far as sending you my code, you are right, I should have posted the code that I tested...

          The problem was in the function "file_put_contents". I was trying other stuff instead of it which didn't work.

          Thanks again very much for the prompt help! 😉

            I thought I replied to this thread, but maybe I didn't. Anyways, don't forget to mark this resolved.

              Write a Reply...