Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,887 questions

51,813 answers

573 users

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
...