File Manipulation Code

  Home arrow File Manipulation Code arrow Free/Used Disk Space
FILE MANIPULATION CODE

Free/Used Disk Space
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2005-07-28

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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 here

    By : 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

    blog comments powered by Disqus

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories

    Developer Shed Affiliates

     



    © 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap