<?php define("DISK","/home/"); //Enter the Drive/Mount point/Directory that you want to generate a space usage graph for. $total = round(disk_total_space(DISK)/1024/1024,2); //Get the total diskspace
$free = round(disk_free_space(DISK)/1024/1024,2); $used = $total - $free; //Find used space
$used = round(($used/$total)*100); //Calculate used space when rounded $free = round(($free/$total)*100); //Calculate free space
//Generate pie chart define("WIDTH", 500); //Width may break if changed define("HEIGHT", 220); //Again height may break it when changed $data[0] = $used; $data[1] = $free;
$img = imagecreate(WIDTH-100, HEIGHT); //Start the images
$background = $white = imagecolorallocate($img, 112,128,144); //Set background $black = imagecolorallocate($img, 0, 0, 0); //Set colours, black in this case
$center_x = (int)WIDTH/2; //Calculate image centre for x $center_y = (int)HEIGHT/2; //Calculate image centre for y
//Draw the pie chart on the percentage of disk space for($i=0; $i<count($data); $i++) { $arclen = (360 * $data[$i]) / 100; imagefilledarc($img, $center_x - 120, $center_y, 200, 200, $last_angle, ($last_angle + $arclen), $color[$i],IMG_ARC_PIE);
$last_angle += $arclen;
}
//Turn the used space into gigabytes $used = round(($used*$total)/100/1024,2); imagestring($img, 5, 250, $center + 30, "Used Space: ".$data[0]."%", $color[0]); //Draw info onto the main shape
imagestring($img, 5, 250, $center + 60, "Free Space: ".$data[1]."%", $color[1]); //Same as above but for free space
header("Content-Type: image/png"); //Content type png
imagepng($img); //Draw image to browser imagedestroy($img); //Destroy the image resource
?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.