tags:

views:

18

answers:

2

Hi.

I'm currently trying to output an image (chart generated with PHP). After I get all the data I need I just output the image to disk with:

imagepng($img, "img/graf.png", 0);
imagedestroy($img); 

Then I call the image on the page, but the browser uses always the cached image instead of the newly generated image. So I am trying to output the image to browser.

Main page is k_b.php. The graph is generated, when I call the file grafico.php with an

include 'grafico.php';

present in k_b.php file. Then I have some code that shows diferent buttons/text depending on other factors, but I must show that chart.

When I try to output the chart directly to the browser I just shows the chart and nothing else. with imagepng($img);

EDIT: Found this online and it seems to work;

ob_start();
imagepng($img);
$contents =  ob_get_contents();
ob_end_clean();
$imagem = "<img src='data:image/png;base64,".base64_encode($contents)."' />";
imagedestroy($img);
A: 

If the script with imagepng($img); sends the image to the browser you can use

<img src="grafico.php" alt="" />

to get the image in a html file.

MatTheCat
Didn't work. Thx anyway. :)
elvispt
That should work, what is in grafico.php ? I think appropriate header is missing.
MatTheCat
A: 

If you want to try again just saving the image to disk and using a normal HML <img> tag to point to it, adding a query string which is different each time should prevent the browser from showing a cached version.

<img src="img/graph.png?<?= time() ?>" />
Sean