jpGraph不能包含PHP文件 [英] jpGraph can't include PHP file

查看:102
本文介绍了jpGraph不能包含PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个PHP文件包含在另一个创建jpGraph图像的PHP文件中

I am trying to include one PHP file in another PHP file that creates a jpGraph image

(原因是我正在为图表加载mySQL数据,并且我想将登录凭据放入单独的文件中)

(The reason is that I am loading mySQL data for the chart, and I want to put the login credentials into a separate file)

我知道图表已创建(因为创建了正确的图像文件),但是该图表未显示在网页中.

I know that the chart is created (because a correct image file is created) but the chart does not show up in the web page.

这是一个简化的代码示例:

Here is a simplified code example:

login.inc.php

login.inc.php

  <?php
  $lhostname="localhost";
  $lusername="joeschmack";
  $lpassword="autumnleaf";
  $ldatabase="customers";
  ?> 

accbarex1.html

accbarex1.html

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title></title>
  </head>
  <body>
    <h3>This is where I want to display my graph</h3>
    <img src="accbarex1.php">
  </body>
</html>

accbarex1.php

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 the graph. These two calls are always required
$graph = new Graph(500,400); 
$graph->SetScale("textlin");

$graph->SetShadow();
$graph->img->SetMargin(40,30,20,40);

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b1plot->value->Show();
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b2plot->value->Show();

// Create the grouped bar plot
$gbplot = new AccBarPlot(array($b1plot,$b2plot));

// ...and add it to the 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 the graph
$graph->Stroke();

//save to file
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);

?>

该文件显示正确的图表,但是网页accbarex1.html显示损坏的图像. 如果我将这一行注释掉

The file shows the correct chart, but the web page accbarex1.html shows a broken image. If I comment out the line

include("./login.inc.php");

然后两者都可以工作.

为什么?在这种情况下,如何包含文件?

Why? And how can I include a file in this situation?

修改 2013年5月13日:

Edit 5-13-2013:

鉴于包含行处于活动状态. 这有帮助(文件和嵌入式图表均可工作)

Given that the include line is active. This helps (both file and embedded chart work)

  • ./login.inc.php不存在
  • ./login.inc.php为空

这无济于事(仅文件有效,嵌入式图表不起作用)

This does not help (only file works, embedded chart does not work)

  • 为包含文件使用绝对路径
  • ./login.inc.php包含以下行 bla//PHP错误
  • ./login.inc.php包含$ i = 1行;//没有PHP错误,没有PHP标签
  • use absolute path for include file
  • ./login.inc.php contains the line bla // PHP error
  • ./login.inc.php contains the line $i=1; // no PHP error, no PHP tags

修改 2013年5月14日:

Edit 5-14-2013:

一些细微的进步:Firefox表现出相同的行为,但是至少我收到一条错误消息.错误控制台显示:

Some slight progress: Firefox shows the same behavior, but at least I get an error message. Error console says:

图片已损坏或被截断:http://.. acbarex1.php

Image corrupt or truncated: http:// .. acbarex1.php

推荐答案

我发现了问题所在.在结束>之后,我还有多余的字符,但是我看不到它们,因为它们是空格和换行符.这些字符弄乱了jpGraph图片.

I found what the problem was. I had extra characters after the closing ?>, but I could not see them because they were spaces and newline. These characters messed up the jpGraph image.

之前:

  <?php
  $lhostname="localhost";
  $lusername="joeschmack";
  $lpassword="autumnleaf";
  $ldatabase="customers";
  ?><SPACE><SPACE><NEWLINE>

之后:

  <?php
  $lhostname="localhost";
  $lusername="joeschmack";
  $lpassword="autumnleaf";
  $ldatabase="customers";
  ?>

解决了!当心多余的字符!

That fixed it! Beware the extra characters!

这篇关于jpGraph不能包含PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆