我想从包含的PHP文件创建一个图像,有一个未定义变量的错误:
的index.php
<?php
// get servers and domains
$serSel = 'SELECT * FROM servers';
$serReq = $connexion->query($serSel);
$serRes = $serReq->fetchAll();
$totalSer = count($serRes);
foreach($serRes as $Serv)
{
$s_global_size = $Serv['s_global_size'];
$s_used_size = $Serv['s_used_size'];
$s_creation = $Serv['s_creation'];
$s_expiry = $Serv['s_expiry'];
$diskSpace = ($e_name == 'domain') ? '-' : format_bytes($s_global_size);
echo $diskSpace;
$diskUsage = ($e_name == 'domain') ? '-' : format_bytes($s_used_size);
echo $diskUsage;
$s_left_size = ($s_global_size - $s_used_size);
$sLeftSize = ($e_name == 'domain') ? '-' : format_bytes($s_left_size);
echo $sLeftSize;
}
echo '<img src="Idara/Statistics/webdata_circle.php">';
&GT;
webdata_circle.php
<?php
// create image
$image = imagecreatetruecolor(180, 180);
$usagePerc = ($diskUsage * 360)/$diskSpace;
// allocate some colors
$red = imagecolorallocate($image, 192, 0, 0);
$red1 = imagecolorallocate($image, 192, 20, 0);
$green = imagecolorallocate($image, 0, 133 ,62);
$green1 = imagecolorallocate($image, 0, 140 ,62);
$trans = imagecolorallocate($image, 0, 0, 0); // transparent background
// Make the background transparent
imagecolortransparent($image, $trans);
imagefilledarc($image, 80, 80, 150, 150, 0, 360, $red, IMG_ARC_PIE);
imagefilledarc($image, 80, 80, 150, 150, 0, $usagePerc, $green, IMG_ARC_PIE);
// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
返回的错误是:
PHP Notice: Undefined variable: diskUsage in webdata_circle.php on line 8
PHP Notice: Undefined variable: diskSpace in webdata_circle.php on line 8
PHP Warning: Division by zero in webdata_circle.php on line 8
提前致谢
注意:这是完整的代码,我希望它会有所帮助
答案 0 :(得分:0)
您需要在第二行的webdata_circle.php
添加以下行:
$diskPath = dirname(__FILE__);
$diskUsage = disk_total_space ($diskPath);
$diskUsage = disk_free_space ($diskPath);