0

I'm trying to display an image on an HTML page using a PHP script in the image/src tag, but the image is broken. When I hard-code the output of getimage.php into the HTML it shows up just fine so I know the base64 encoding is correct. The page that shows the image needs to be HTML.

PHP:

    <?php
        header("Content-type: image/png");
        $data = file_get_contents('arbitrary.png');
        $base64 = 'data:image/png;base64,'.base64_encode($data);
        echo $base64;
    ?>

HTML:

<html> <body> <img src="getimage.php" /> </body> </html>

Any ideas? Thanks in advance!

Edited by pritaeas: Moved to web dev.

2
Contributors
1
Reply
13
Views
1 Year
Discussion Span
Last Post by Tpojka
0

PHP interpreter doesn't check .html pages unless stated otherwise.
In Apache2@Ubuntu/Debian use this directive in .htaccess file.

AddType application/x-httpd-php .html .htm

or

AddType application/x-httpd-php5 .html .htm

If you are running PHP as CGI, you should write

AddHandler application/x-httpd-php .html .htm

or

AddHandler application/x-httpd-php5 .html .htm

Solution from here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.