-1

以下のこのリンクを見てください..

http://www.7tech.co.in/php/how-to-generate-a-graph-image-in-php/

以下のコードはどういう意味ですか?

header("Content-type:image/png");
 imagepng($img);

この2行を実装しようとすると、「ヘッダー情報を変更できません-ヘッダーは既に送信されました...」というエラーが表示され、コメントするとエラーはありませんが、グラフが表示されません..

うーん、誰かそれが何を意味するのか知っていますか、私に説明してもらえますか? 申し訳ありませんが、私はPHPに非常に慣れていません..事前に感謝します!

4

2 に答える 2

2

The error you're receiving is informing you that you cannot change the response headers to image/png, because they've already be set and sent. Make sure the header() line is the very first line in your output. You cannot output anything before it.

As for the second line, imagepng(), this is used for outputting a portable-network graphic. The $img variable would be the image resource that would have been built earlier. The following is an extremely basic example using both of these lines:

<?php

  // Gets an image resource
  $im = imagecreatefrompng("test.png");

  // Tells the recipient we're sending image data
  header('Content-Type: image/png');

  // Output the PNG image data
  imagepng($im);

  // Cleanup
  imagedestroy($im);

?>
于 2012-05-28T04:54:57.750 に答える
0

When you get the "Cannot modify header information" error message, it could mean that you have unnecessary line breaks, other spacing, or code between the opening PHP tag and your header call... it must always be the very first thing you call and should not be set more than once.

于 2012-05-28T04:56:35.123 に答える