note 72281 added to function.disk-free-space
| From: | Nitrogen at osu1 dot php dot net | Date: | Thu, 11 Jan 2007 01:50:45 +0000 |
| Subject: | note 72281 added to function.disk-free-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121549@lists.php.net to get a copy of this message | ||
Another easy way to convert bytes to human readable sizes would be this:
<?php
function HumanSize($Bytes)
{
$Type=array("", "kilo", "mega", "giga", "tera",
"peta", "exa", "zetta", "yotta");
$Index=0;
while($Bytes>=1024)
{
$Bytes/=1024;
$Index++;
}
return("".$Bytes." ".$Type[$Index]."bytes");
}
?>
It simply takes the $Bytes and divides it by 1024 bytes untill it's no longer over or equal to
1024, meanwhile it increases the $Index to allocate which suffix belongs to the return (adding
'bytes' to the end to save some space).
You can easily modify it so it's shorter, but I made it so it's more clearer.
Nitrogen.
----
Server IP: 216.194.113.175
Probable Submitter: 85.210.178.83
----
Manual Page -- http://www.php.net/manual/en/function.disk-free-space.php
Edit -- https://master.php.net/note/edit/72281
Del: integrated -- https://master.php.net/note/delete/72281/integrated
Del: useless -- https://master.php.net/note/delete/72281/useless
Del: bad code -- https://master.php.net/note/delete/72281/bad+code
Del: spam -- https://master.php.net/note/delete/72281/spam
Del: non-english -- https://master.php.net/note/delete/72281/non-english
Del: in docs -- https://master.php.net/note/delete/72281/in+docs
Del: other reasons-- https://master.php.net/note/delete/72281
Reject -- https://master.php.net/note/reject/72281
Search -- https://master.php.net/manage/user-notes.php