Draws a simple GD pie chart showing used space over total space. Requires GD of course.
You can also find more scripts on my site
hereBy : andrew
<?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
imagerectangle($img, 0, 0, WIDTH-101, HEIGHT-1, $black); //Draw the backrgound border
$color[0] = imagecolorallocate($img, 159,182,205);
$color[1] = imagecolorallocate($img, 198,226,255);
$last_angle = 0;
//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
imagerectangle($img, 240, $center+10, 390, $center+100, $black);
imagestring($img, 5, $center_x, $center + 200,
$used."Gb / ".($total/1024)."Gb", $black);
// Used space / Total 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. |
More File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
This tutorial applies the concepts that were covered in the first part of this two-part series to a real-world example. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
You might know that you can pull XML data into OpenOffice's spreadsheet program, Calc, but did you know that you can create a filter to make word-processing documents out of data stored as XML? This tutorial shows you how to use OpenOffice's import/export filters to open your XML data as though it's just a plain document. From there, users can edit the document much more naturally and then save it back to its native format. You can also use this feature to easily turn your documents into XML data. FREE! Go There Now!
|
|
|
|
IBM DB2 9.5 provides new options for tighter security, and allows for more granularity and flexibility in administration of the database. This tutorial is the first of two tutorials that cover roles and trusted contexts. Follow the exercises in this tutorial, and learn how to take advantage of the new DB2 feature roles in combination with other essential e-business technologies such as Web services, Web application server, and DB2 database server. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
Learn how IBM Rational Tester for SOA Quality addresses IBM WebSphere MQ with Web services. You get hands-on experience in creating a test, handling the WebSphere MQ series protocol, configuring the test, and then replaying it. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |