Decoder data: image / png; base64 with PHP

0

I need to generate the image converted by the base64 string. I have the following code, but when accessed via browser, it generates several invalid characters.

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

    $decoded = base64_decode($string);

    echo $decoded;

    ?>
    
asked by anonymous 15.02.2018 / 19:17

1 answer

1

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

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

List of MimeTypes you can use.

    
15.02.2018 / 19:31