jpgraph的错误:HTTP标头已经发送(JpGraph Error: HTTP headers

2019-06-25 08:47发布

问题是,JpGraph的不是我的网页上正确显示。 奇怪的是,如果我单独运行上面的代码,然后它的作品。 但是,如果我在我的主代码中插入它时,它失败产生上面显示的消息。 PS我使用“ob_start();”,但它并没有解决问题。

 // 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". 

Answer 1:

JpGraphs不能在文件与HTML存在。 他们必须在纯PHP文件。 为了解决这个问题,我创建了一个生成的图表一个单独的文件,并提出了整个事情的功能。 最后,变化

$graph->Stroke();

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

然后,在你的index.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文件:

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

希望这对你的作品。



Answer 2:

你甚至可以做同样的HTML文档中 - 先写图形到一个文件,然后显示它...

 //Code generating your graph here ... // Finally output the image to a file $graph->Stroke("/var/www/html/tmp/out.jpg"); //end of php code ?> <!-- now include the newly generated image in the HTML --> <img src="/tmp/out.jpg"> </body> </html> 



Answer 3:

它似乎是由函数创建的JPEG文件不能超过写在我的情况下...

做覆盖它。我改变了我的jpgraph的文件gd_image.inc.php ..你必须注释掉这行JpGraphError::RaiseL(25111,$aStrokeFileName)



文章来源: JpGraph Error: HTTP headers have already been sent
标签: html jpgraph