mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
file size encode method added
This commit is contained in:
@@ -393,4 +393,48 @@ class e_file
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse bytes to human readable format
|
||||||
|
* Former Download page function
|
||||||
|
* @param mixed $size file size in bytes or file path if $retrieve is true
|
||||||
|
* @param boolean $retrieve defines the type of $size
|
||||||
|
*
|
||||||
|
* @return string formatted size
|
||||||
|
*/
|
||||||
|
function file_size_encode($size, $retrieve = false)
|
||||||
|
{
|
||||||
|
if($retrieve)
|
||||||
|
{
|
||||||
|
$size = filesize($size);
|
||||||
|
}
|
||||||
|
$kb = 1024;
|
||||||
|
$mb = 1024 * $kb;
|
||||||
|
$gb = 1024 * $mb;
|
||||||
|
$tb = 1024 * $gb;
|
||||||
|
if(!$size)
|
||||||
|
{
|
||||||
|
return '0 '.CORE_LAN_B;
|
||||||
|
}
|
||||||
|
if ($size < $kb)
|
||||||
|
{
|
||||||
|
return $size." ".CORE_LAN_B;
|
||||||
|
}
|
||||||
|
else if($size < $mb)
|
||||||
|
{
|
||||||
|
return round($size/$kb, 2)." ".CORE_LAN_KB;
|
||||||
|
}
|
||||||
|
else if($size < $gb)
|
||||||
|
{
|
||||||
|
return round($size/$mb, 2)." ".CORE_LAN_MB;
|
||||||
|
}
|
||||||
|
else if($size < $tb)
|
||||||
|
{
|
||||||
|
return round($size/$gb, 2)." ".CORE_LAN_GB;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return round($size/$tb, 2)." ".CORE_LAN_TB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user