note 68080 deleted from function.disk-free-space by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:58:34 +0000 |
| Subject: | note 68080 deleted from function.disk-free-space by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197259@lists.php.net to get a copy of this message | ||
Note Submitter: djneoform at gmail dot com
----
List all drives, free space, total space and percentage free.
<?
for ($i = 67; $i <= 90; $i++)
{
$drive = chr($i);
if (is_dir($drive.':'))
{
$freespace = disk_free_space($drive.':');
$total_space = disk_total_space($drive.':');
$percentage_free = $freespace ? round($freespace / $total_space, 2) * 100 : 0;
echo $drive.': '.to_readble_size($freespace).' /
'.to_readble_size($total_space).' ['.$percentage_free.'%]<br />';
}
}
function to_readble_size($size)
{
switch (true)
{
case ($size > 1000000000000):
$size /= 1000000000000;
$suffix = 'TB';
break;
case ($size > 1000000000):
$size /= 1000000000;
$suffix = 'GB';
break;
case ($size > 1000000):
$size /= 1000000;
$suffix = 'MB';
break;
case ($size > 1000):
$size /= 1000;
$suffix = 'KB';
break;
default:
$suffix = 'B';
}
return round($size, 2).$suffix;
}
?>