Find Storage Details of Server using PHP

by Sasikumar 2014-07-22 11:05:37

We can find the storage details of the server in php using the following code

PHP Code:
$free_disk = disk_free_space("/var/www");
$total_disk = disk_total_space("/var/www");
$used_disk = $total_disk - $free_disk;
$percent_disk = sprintf('%.2f',($used_disk / $total_disk) * 100);

echo "Free Space: ".$free_disk = formatSize($free_disk);
echo "<br>";
echo "Used Space: ".$used_disk = formatSize($used_disk);
echo "<br>";
echo "Total Space: ".$total_disk = formatSize($total_disk);
echo "<br>";

function formatSize( $bytes )
{
    $types = array( 'B', 'KB', 'MB', 'GB', 'TB' );
    for( $i = 0; $bytes >= 1024 && $i < ( count( $types ) -1 ); $bytes /= 1024, $i++ );
        return( round( $bytes, 2 ) . " " . $types[$i] );
}
This code finds the space (storage) details in which this code is being run, for example in the server in which this code made to run.
 
1150
like
0
dislike
0
mail
flag

You must LOGIN to add comments