How to use disk_total_space() function to get the disk size in PHP

2 Answers

0 votes
$c = disk_total_space("c:");
$d = disk_total_space("d:");

echo "disk c total space = $c<br />";
echo "disk d total space = $d<br />";

/*
run:

disk c total space = 127456505856
disk d total space = 1000202039296
 
*/

 



answered Apr 19, 2016 by avibootz
0 votes
function formatBytes($bytes, $precision = 2) 
{ 
    if  ($bytes == 0) return '0 B';
    $sizes = array('B', 'KB', 'M', 'GB', 'TB');   
    $base = log($bytes, 1024);
 
    return round(pow(1024, $base - floor($base)), $precision) . ' ' . $sizes[floor($base)];
}    
   
$c = disk_total_space("c:");
$d = disk_total_space("d:");

echo "disk c total space = ".formatBytes($c)."<br />";
echo "disk c total space = ".formatBytes($d)."<br />";

/*
run:

disk c total space = 118.7 GB
disk c total space = 931.51 GB
 
*/

 



answered Apr 19, 2016 by avibootz
...