html - jpGraph can't include PHP file -
i trying include 1 php file in php file creates jpgraph image
(the reason loading mysql data chart, , want put login credentials separate file)
i know chart created (because correct image file created) chart not show in web page.
here simplified code example:
login.inc.php
<?php $lhostname="localhost"; $lusername="joeschmack"; $lpassword="autumnleaf"; $ldatabase="customers"; ?>
accbarex1.html
<html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title></title> </head> <body> <h3>this want display graph</h3> <img src="accbarex1.php"> </body> </html>
accbarex1.php
<?php // content="text/plain; charset=utf-8" require_once ('../../../lib/jpgraph/jpgraph.php'); require_once ('../../../lib/jpgraph/jpgraph_bar.php'); include("./login.inc.php"); $data1y=array(-8,8,9,3,5,6); $data2y=array(18,2,1,7,5,4); // create graph. these 2 calls required $graph = new graph(500,400); $graph->setscale("textlin"); $graph->setshadow(); $graph->img->setmargin(40,30,20,40); // create bar plots $b1plot = new barplot($data1y); $b1plot->setfillcolor("orange"); $b1plot->value->show(); $b2plot = new barplot($data2y); $b2plot->setfillcolor("blue"); $b2plot->value->show(); // create grouped bar plot $gbplot = new accbarplot(array($b1plot,$b2plot)); // ...and add graph $graph->add($gbplot); $graph->title->set("accumulated bar plots"); $graph->xaxis->title->set("x-title"); $graph->yaxis->title->set("y-title"); //$graph->title->setfont(ff_font1,fs_bold); //$graph->yaxis->title->setfont(ff_font1,fs_bold); //$graph->xaxis->title->setfont(ff_font1,fs_bold); // display graph $graph->stroke(); //save file $filename = "/tmp/imagefile.png"; $graph->img->stream($filename); ?>
the file shows correct chart, web page accbarex1.html shows broken image. if comment out line
include("./login.inc.php");
then both work.
why? , how can include file in situation?
edit 5-13-2013:
given include line active. helps (both file , embedded chart work)
- ./login.inc.php not exist
- ./login.inc.php empty
this not (only file works, embedded chart not work)
- use absolute path include file
- ./login.inc.php contains line bla // php error
- ./login.inc.php contains line $i=1; // no php error, no php tags
edit 5-14-2013:
some slight progress: firefox shows same behavior, @ least error message. error console says:
image corrupt or truncated: http:// .. acbarex1.php
i found problem was. had characters after closing ?>, not see them because spaces , newline. these characters messed jpgraph image.
before:
<?php $lhostname="localhost"; $lusername="joeschmack"; $lpassword="autumnleaf"; $ldatabase="customers"; ?><space><space><newline>
after:
<?php $lhostname="localhost"; $lusername="joeschmack"; $lpassword="autumnleaf"; $ldatabase="customers"; ?>
that fixed it! beware characters!
Comments
Post a Comment