This class is quick and simple to install into any PHP application, and is easy to customise to the display you require.
The script finds the amount of total disk space on your system, and then the total free space. We then calculate the used space and give it to you as a percentage.
This class was developed by Fred Bradley - http://twitter.com/fredbradley
You can choose the path of the disk that you want to check (if you have multiple disks mounted, for example). You can do this by setting the first paramater when calling calling the Class to the directory that you want to check. EG: $disk = new DiskSpaceCheck('/var/www/vhosts/');
- Add the
class.DiskSpaceCheck.php
to you filesystem. - In your file that you wish to use this script create a new OO instsance of the class.
$disk = new DiskSpaceCheck();
- When you do this you will find 4 new variables available for you to pop into your frontend.
$disk->total_space
$disk->free_space
$disk->used_space
$disk->percent
- There is also one function that included which is
$disk->formatBytes($bytes, $precision=2)
this will automatically translate the thousands of bytes digits into a simple to read MB, or GB - or even TB for you.
Here is a quick example markup using Bootstrap.
<div class="push-bit"> <span class="pull-right"> <small><?php echo floor($disk->percent); ?>%</small> </span> <small><strong><?php echo $disk->formatBytes($disk->used_space); ?></strong> / <?php echo $disk->formatBytes($disk->total_space); ?></small> </div> <div class="progress progress-mini push-bit"> <div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="<?php echo $disk->percent; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $disk->percent; ?>%"></div> </div>
1.0.0