不能显示图片???

chen_pei 2009-02-03 09:50:22
<?php
error_reporting(E_ALL);
for ($i=0;$i<4;$i++)
{
$rand.=dechex(rand(1,15));
}
$im= ImageCreateTrueColor(100, 30);
//设置颜色
$bg=ImageColorAllocate($im, 0, 0, 0);
$te=ImageColorAllocate($im, 255, 255, 255);
//把字符串写在图象左上角
ImageString ($im, 5,0,0,$rand,$te);
//输出图象
header ('Content-type: image/png');
ImagePng($im);
ImageDestroy($im);
?>
...全文
57 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luobo525 2009-02-04
  • 打赏
  • 举报
回复
error_reporting 包含 notice 吧
因为 header ('Content-type: image/png'); 有这句 所以不会显示notice信息了
Zijian_Zhang 2009-02-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chen_pei 的回复:]
谢谢!不过有这条代码error_reporting(E_ALL);
怎么不会报错呢??
[/Quote]

呵呵,error_reporting(E_ALL);这个E_ALL是不包括E_NOTICE的。

E_ALL的PHP官方定义:

All errors and warnings。

只有所有的Error和Warnings,没有Notice级别的。

而,未定义变量属于Notice的。
chen_pei 2009-02-03
  • 打赏
  • 举报
回复
谢谢!不过有这条代码error_reporting(E_ALL);
怎么不会报错呢??
Zijian_Zhang 2009-02-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 chen_pei 的帖子:]
PHP code<?phperror_reporting(E_ALL);for($i=0;$i<4;$i++)
{$rand.=dechex(rand(1,15));
}$im=ImageCreateTrueColor(100,30);//设置颜色$bg=ImageColorAllocate($im,0,0,0);$te=ImageColorAllocate($im,255,255,255);//把字符串写在图象左上角ImageString ($im,5,0,0,$rand,$te);//输出图象header('Content-type: image/png');
ImagePng($im);
ImageDestroy($im);?>
[/Quote]

你的$rand没有定义啊!

楼主把代码改为:

<?php
error_reporting(E_ALL);
$rand=0;
for ($i=0;$i<4;$i++)
{
$rand.=dechex(rand(1,15));
}
$im= ImageCreateTrueColor(100, 30);
//设置颜色
$bg=ImageColorAllocate($im, 0, 0, 0);
$te=ImageColorAllocate($im, 255, 255, 255);
//把字符串写在图象左上角
ImageString ($im, 5,0,0,$rand,$te);
//输出图象
header ('Content-type: image/png');
ImagePng($im);
ImageDestroy($im);
?>


这样就可以了。

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧