Showing posts with label disk space. Show all posts
Showing posts with label disk space. Show all posts

Friday 18 May 2018

How to find disk space in PHP?

<?php
$bytes = disk_total_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
//echo $bytes . '<br />';
$total = sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];

$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
//echo $bytes . '<br />';
$free = sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];

   $used = (float)$total-(float)$free;
echo "Total Space : $total <br/> Available Space : $free <br/> Used Space : $used ".$si_prefix[$class];
?>