首頁 > 後端開發 > php教程 > 为啥无法输出一张图片

为啥无法输出一张图片

WBOY
發布: 2016-06-13 12:29:39
原創
836 人瀏覽過

为什么无法输出一张图片

	session_start();<br />
	<br />
	//随机码的个数<br />
	//$_rnd_code = 4;<br />
	<br />
	//创建随机码<br />
	for($i=0;$i<4;$i++){<br />
		$_nmsg.=dechex(mt_rand(0,15));<br />
	}<br />
	<br />
	//保存session<br />
	$_SESSION['code']=$_nmsg;<br />
	<br />
	//长和高<br />
	$_width = 75;<br />
	$_height = 25;<br />
	<br />
	//创建一张图像<br />
	$_img = imagecreatetruecolor($_width,$_height);<br />
<br />
	<br />
<br />
	//输出图像<br />
	header('Content-Type:image/png');<br />
	imagepng($_img);
登入後複製

输出结果为
<br /><br />
<b>Notice</b>:  Undefined variable: _rnd_code in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  Division by zero in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _heght in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  mt_rand(): max(0) is smaller than min(1) in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _rnd_code in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  Division by zero in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _heght in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  mt_rand(): max(0) is smaller than min(1) in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _rnd_code in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  Division by zero in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _heght in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  mt_rand(): max(0) is smaller than min(1) in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _rnd_code in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  Division by zero in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _heght in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  mt_rand(): max(0) is smaller than min(1) in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _rnd_code in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  Division by zero in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Notice</b>:  Undefined variable: _heght in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
<br /><br />
<b>Warning</b>:  mt_rand(): max(0) is smaller than min(1) in <b>D:\AMP\web\ide_tmp.php</b> on line <b>53</b><br /><br />
‰PNG<br />

登入後複製
按错误信息修改
然后得:
仍然是不友好的“验证码”图片
将header注释掉,打开错误就可以看到错误。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板