note 112995 deleted from function.filesize by googleguy
| From: | googleguy@php.net | Date: | Fri, 16 Aug 2013 10:57:36 +0000 |
| Subject: | note 112995 deleted from function.filesize by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195986@lists.php.net to get a copy of this message | ||
Note Submitter: Arseny Mogilev
----
<?php
/**
* Converts bytes into human readable file size.
*
* @param string $bytes
* @return string human readable file size (2,87 Ðб)
* @author Mogilev Arseny
*/
function FileSizeConvert($bytes)
{
$bytes = floatval($bytes);
$arBytes = array(
0 => array(
"UNIT" => "Тб",
"VALUE" => pow(1024, 4)
),
1 => array(
"UNIT" => "Ðб",
"VALUE" => pow(1024, 3)
),
2 => array(
"UNIT" => "Ðб",
"VALUE" => pow(1024, 2)
),
3 => array(
"UNIT" => "Ðб",
"VALUE" => 1024
),
4 => array(
"UNIT" => "Ð",
"VALUE" => 1
),
);
foreach($arBytes as $arItem)
{
if($bytes >= $arItem["VALUE"])
{
$result = $bytes / $arItem["VALUE"];
$result = str_replace(".", "," , strval(round($result, 2)))."
".$arItem["UNIT"];
break;
}
}
return $result;
}
?>