JpGraph错误:HTTP标头已被发送 [英] JpGraph Error: HTTP headers have already been sent

查看:107
本文介绍了JpGraph错误:HTTP标头已被发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是JpGraph无法在我的网页上正确显示.奇怪的是,如果我单独运行上面的代码,那么它将起作用.但是,如果我将其插入到我的主代码中,它将无法生成上述消息. P.S.我正在使用"ob_start();",但不能解决问题.

The problem is that the JpGraph is not displayed correctly on my web-page. The strange thing is that if I run the above code in isolation, then it works. But if I insert it in my main code, it fails producing the above-shown message. P.S. I'm using 'ob_start();', but it does not solve the problem.

// A new graph with automatic size
$graph = new GanttGraph (0,0, "auto");

//  A new activity on row '0'
$activity = new GanttBar (0,"Project", "2001-12-21", "2002-02-20");
$graph->Add( $activity);

// Display the Gantt chart
$graph->Stroke();
?> 
</div>

JpGraph Error: HTTP headers have already been sent.
Caused by output from file index.php at line 85.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).

Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

For example it is a common mistake to leave a blank line before the opening "<?php".

推荐答案

使用html的文件中不存在JpGraph.他们必须在一个纯PHP文件中.为了解决这个问题,我创建了一个单独的文件来生成图形,并将整个对象作为一个函数.最后,更改

JpGraphs can't exist in files with html. They have to be in a pure php file. To get around this, I created a seperate file that generates the graph, and made the whole thing a function. At the end, change

$graph->Stroke();

$graph->Stroke(".<filepaht>.jpg");

然后,在您的index.php页面中,引用图像文件.

Then, in your index.php page, reference the image file.

所以,看起来您需要的是

So, what it looks like you need is,

createjpgraph.php:

createjpgraph.php:

<?php 
function GenGraph (<input variables>) {

    // A new graph with automatic size        
    $graph = new GanttGraph (0,0, "auto");        

    //  A new activity on row '0'        
    $activity = new GanttBar (0,"Project", "2001-12-21", "2002-02-20");        
    $graph->Add( $activity);        

    // Display the Gantt chart        
    $graph->Stroke("./foler/file.jpg");
}
?> 

index.php:

index.php:

...
<div>
...
<?php
include 'createjpgraph.php';
GenerateGraph(<variables>);
?>
<img src=\"./folder/file.jpg\" />
</div>

希望这对您有用.

这篇关于JpGraph错误:HTTP标头已被发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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