Commit bc360fdb authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3064 Added a function for human readable sizes used in FAI

No related merge requests found
Showing with 30 additions and 0 deletions
+30 -0
...@@ -2252,6 +2252,36 @@ function to_byte($value) { ...@@ -2252,6 +2252,36 @@ function to_byte($value) {
} }
} }
/*!
* \brief Convert a size in bytes to a human readable version
*
* \param float $bytes size in bytes
*
* \param int $precision number of digits after comma, default is 2
*
* \return Returns something like '9.77KiB' for arguments (10000, 2)
*/
function humanReadableSize ($bytes, $precision = 2)
{
$format = array(
_('%sB'),
_('%sKiB'),
_('%sMiB'),
_('%sGiB'),
_('%sTiB'),
_('%sPiB'),
_('%sEiB'),
_('%sZiB'),
_('%sYiB')
);
if ($bytes == 0) {
return sprintf($format[0], '0');
}
$base = log($bytes) / log(1024);
return sprintf($format[floor($base)], round(pow(1024, $base - floor($base)), $precision));
}
/*! /*!
* \brief Check if a value exists in an array (case-insensitive) * \brief Check if a value exists in an array (case-insensitive)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment