note 56030 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:14:50 +0000 |
| Subject: | note 56030 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98299@lists.php.net to get a copy of this message | ||
Note Submitter: Afterlife69[at]GamerzVault.com
----
Heres the function i made.
<?php
// Function
function size_translate($filesize)
{
$array = array(
'YB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
'ZB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
'EB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
'PB' => 1024 * 1024 * 1024 * 1024 * 1024,
'TB' => 1024 * 1024 * 1024 * 1024,
'GB' => 1024 * 1024 * 1024,
'MB' => 1024 * 1024,
'KB' => 1024,
);
if($filesize <= 1024)
{
$filesize = $filesize . ' Bytes';
}
foreach($array AS $name => $size)
{
if($filesize > $size || $filesize == $size)
{
$filesize = round((round($filesize / $size * 100) / 100), 2) . ' ' . $name;
}
}
return $filesize;
}
// Example
echo size_translate(1024 * 1024 * 1024 * 1024 * 1024 * 4.95); // Returns: 4.95 Petabytes
?>
Btw, you guys need to learn how to code clean.