0
votes

I'm using the JpGraph library within a Zend Framework project of version 1.11. I'm trying to display the graph of some data using an img tag by including a php script in the src field, as so:

echo "<img src='vgraph.php?param1=val1&param2=val2...

When I do this, the only thing displayed as an image is the my browser's default broken image. Since typical URLs in Zend are treated as controller-action pairs, the path to the file I am including is also treated as a controller-action pair. To investigate why I wasn't getting my image, I viewed the source of the page in the browser. When I clicked on the link for the above img tag, I was directed to a page containing the error:

Invalid controller specified (vgraph.php)

I don't by any means intend to use the script as a controller. It is only supposed to display the image of a graph. I am unsure about how to make sure that Zend only uses the file's output as an image, and not to use its path as a URL.

Here is the file I am using for the image, vgraph.php:

<?php

/* graph the vital data */

require_once( 'path/to/Zend/project/web/library/jpgraph/jpgraph.php' ); 
require_once( 'path/to/Zend/project/web/library/jpgraph/jpgraph_line.php' );

/* get the needed parameters */
$id = $_GET['param1'];
$type = $_GET['param2'];
$from = $_GET['param3'];
$to = $_GET['param4'];

$graph = new Graph( $width, $height );

/* create the data and plot */
$obj = new CcFunc_VitalSigns();
$vitals = $obj->getVitalData( $id, $type, $from, $to );

/* configure everything */
$graph->setScale( 'intint' );
$graph->title->Set( "Graph of " . $type );
$graph->xaxis->title->Set( "X-Axis" );
$graph->yaxis->title->Set( "Numerical Value" );

$lp = new LinePlot( $vitals );
$lp->setColor( 'blue' );    
$lp->setWeight( 5 );

/* add the plot to the graph */
$graph->Add( $lp );

/* display the graph */
$graph->Stroke();

NOTE: I've tried other solutions, such as streaming the graph to a png file and letting the src field be the URL of that file, but I was met with the same problem, even after adding a RewriteRule to apache to prevent redirection of .png files. I've settled upon this method as the most comfortable (potential) solution.

EDIT: I didn't say this before, but the code where the img tag is echo'd is not a controller, and is actually located in path/to/Zend/roject/web/application/scripts/views. The script vgraph.php is located in path/to/Zend/project/web/library.

2
Where is the vgraph.php file located, and what does your htaccess file look like?Tim Fountain
I added the file locations in the edit.trifork

2 Answers

1
votes

You need to move the vgraph.php file to your public folder for this to work, the browser isn't able to view files outside of that.

Move it to path/to/Zend/project/web/public/vgraph.php, change your img tag to <img src="/vgraph.php?param1=val1&param2=val2... and everything should work as you expect.

-1
votes

When linking try in the view to specify the full path as:

<?php echo $this->baseURL();?> 

Zend View Helpers

This will return localhos/[APP]/

Hope this helps

Try to put everything in a Graph controller within a generateAction method and you can link to it:

<a href="<?php echo $this->baseURL();?>/graph/generate/?param1=val1&param2=val2...">Generate</a>