[rrd-users] Re: png file as php script

Dan Cech dcech at phpwerx.net
Fri Oct 13 13:28:49 MEST 2006


Sebastian Pachuta wrote:
> Hi rrd-users,
> 
> I have odd idea about image generation:
> 
> 1/
> using .htaccess change apache config to parse png files as php scripts
> 
> 2/
> create file graph-monthly.png which will be php script who:
>  - will send appropriate png headers
>  - call rrd_graph to generate images
>  - push image file to browser
> 
> Problem is that I cannot use 'exec, shell_exec, system, passthru'
> php functions.
> 
> My question:
> Is there any way to call :graph (using rrd php module) and get
> output (image) in php variable?

Yes,

// graph configuration
$cfg = array();

//temporary file for rrd_graph to write to
$graph_file = tempnam('/tmp','rrdgraph');

// generate graph
$result = rrd_graph($graph_file,$cfg,count($cfg));
if (!is_array($result)) {
	display rrd_error() here
}

// output headers
header('Content-Type: image/png');
header('Content-Length: '. filesize($graph_file));

// dump the graph
$fp = fopen($graph_file,'rb');
fpassthru($fp);

Dan

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the rrd-users mailing list