我在试图建立一个图像函数,出现:Cannot modify header information

来源:百度知道 编辑:UC知道 时间:2024/06/19 04:24:33
我在试图建立一个图像函数如下:

<?php
// 建立一幅 100X30 的图像
$im = imagecreatetruecolor(100, 30);

// 设置背景颜色
$bg = imagecolorallocate($im, 0, 0, 0);
//设置字体颜色
$textcolor = imagecolorallocate($im, 0, 255, 255);

// 把字符串写在图像左上角
imagestring($im, 5, 0, 0, "Hello world!", $textcolor);

// 输出图像
header("Content-type: image/jpeg");
imagejpeg($im);
?>

结果就出现 Warning: Cannot modify header information - headers already sent by (output started at f:\我的学习

\it\php\web\form\time\time.php:8) in f:\我的学习\it\php\web\form\time\time.php on line 43
43行就是:header("Content-type: image/jpeg");
这是怎么回事?我已经按照要求把extension=php_gd2.dll前面的;去掉了,还是不行,我发现一有头文件header("Content-type:

image/jpeg");这样的信息,就会出现这样的问题,怎样调整?

这是你从文件里摘出来的一部分还是整个文件?
如果是整个文件这个程序是完全正常的,如果是嵌在html中的,会出现你所说的错误,具体的解决方法请参见我之前的回答:

http://zhidao.baidu.com/question/12000285.html