Decoder data:image/png;Base64 with PHP

Asked

Viewed 940 times

0

I need to generate the image converted by string Base64. I have the code below, but when accessing via browser, generates several invalid characters.

<?php
    $string  = 'hOjo6uPnmm1Gr1fT29tLU1IQoinLUMbdAJJvNEgqFOH78uJxbGI/HEQQBlUpFJpNBrVbzwAMPYDQaAdi3bx+PP/74511dXa9lMpk0MAb8YAWw3yIAcmQGyubOcPFAiAmCYKmqqnryoYceutnr9fLee+/x2WefUVNTQ2Njo+ygSaf.......';

    $decoded = base64_decode($string);

    echo $decoded;

    ?>

1 answer

1


It is necessary that your server "inform" to the browser that it (the server) is sending an image, for this it is necessary to include the header Content-Type: image/jpeg, for example.

header("Content-Type: image/png");
echo $decoded;

List of Mimetypes that you can use.

  • Good. That’s right. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.