【问题标题】:JpGraph Error: HTTP headers have already been sentJpGraph 错误:HTTP 标头已发送
【发布时间】:2023-03-11 08:12:01
【问题描述】:

问题是 JpGraph 没有正确显示在我的网页上。奇怪的是,如果我单独运行上面的代码,那么它就可以工作。但是如果我将它插入到我的主代码中,它将无法生成上面显示的消息。 附言我正在使用'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".

【问题讨论】:

    标签: html jpgraph


    【解决方案1】:

    在我的情况下,似乎无法覆盖该函数正在创建的 jpeg 文件...

    覆盖它.. 我更改了我的 JPGraph 文件 gd_image.inc.php .. 你必须注释掉该行 上面写着JpGraphError::RaiseL(25111,$aStrokeFileName)

    【讨论】:

      【解决方案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>

      【讨论】:

        【解决方案3】:

        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>
        

        希望这对你有用。

        【讨论】:

          猜你喜欢
          • 2011-07-04
          • 2015-06-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-03
          • 2013-10-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多