Home > Backend Development > PHP Tutorial > 我的php验证码出现这样的问题:Image corrupt or truncated

我的php验证码出现这样的问题:Image corrupt or truncated

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:03:12
Original
1202 people have browsed it

我的php验证码出现这样的问题:
                         Image corrupt or truncated: http://localhost/htsys/?c=login&m=yzm
无论我怎么调试始终无法正常显示验证码图片,提示图像由于自身原因无法显示......
纠结了


回复讨论(解决方案)

尝试1.图像路径问题,改绝对路径,或者在相同的路径下放一张静态图,如果能显示则排除。
尝试2.图像编码,是否是生成时有问题,生成图像的代码,一行一行的调试。

生成图像的代码没有问题,我换了好多验证码类,还是这样,无语呀,

public function yzm(){					//登录页面验证码的方法		header("content-type:image/png");		$num = $_GET['num'];		$imagewidth=50;		$imageheight=20;		$numimage = imagecreate($imagewidth,$imageheight);		imagecolorallocate($numimage,238,97,85);		for($i=0;$i<strlen($num);$i++){			$x = mt_rand(1,8)+$imagewidth*$i/4;			$y = mt_rand(1,$imageheight/4);			$color=imagecolorallocate($numimage,mt_rand(0,90),mt_rand(0,80),mt_rand(0,120));			imagestring($numimage,5,$x,$y,$num[$i],$color);		}		for($i=0;$i<200;$i++){			$randcolor=imagecolorallocate($numimage,rand(200,255),rand(180,255),rand(240,255));			imagesetpixel($numimage,rand()%70,rand()%20,$randcolor); 		}		imagepng($numimage);		imagedestroy($numimage);	} 	
Copy after login


我从路径上面得到一个num的随机字符串然后让yzm函数获取生成,就这么简单,真的不知道为什么,才开始还好好的,

public function yzm(){				header("content-type:image/png");		$num = $_GET['num'];		$imagewidth=50;		$imageheight=20;		$numimage = imagecreate($imagewidth,$imageheight);		imagecolorallocate($numimage,238,97,85);		for($i=0;$i<strlen($num);$i++){			$x = mt_rand(1,8)+$imagewidth*$i/4;			$y = mt_rand(1,$imageheight/4);			$color=imagecolorallocate($numimage,mt_rand(0,90),mt_rand(0,80),mt_rand(0,120));			imagestring($numimage,5,$x,$y,$num[$i],$color);		}		for($i=0;$i<200;$i++){			$randcolor=imagecolorallocate($numimage,rand(200,255),rand(180,255),rand(240,255));			imagesetpixel($numimage,rand()%70,rand()%20,$randcolor); 		}		imagepng($numimage);		imagedestroy($numimage);	} 
Copy after login

这样的问题太假了,终于解决了,但是我还不知道究竟是哪的问题

这样的问题 很大的原因是 在输出的前面出现了 空白输出 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template