Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
fusiondirectory
Commits
bc360fdb
Commit
bc360fdb
authored
10 years ago
by
Côme Bernigaud
Committed by
Benoit Mortier
10 years ago
Browse files
Options
Download
Patches
Plain Diff
Fixes #3064 Added a function for human readable sizes used in FAI
parent
a4907eac
fusiondirectory-1.0.7.5
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/functions.inc
+30
-0
include/functions.inc
with
30 additions
and
0 deletions
+30
-0
include/functions.inc
+
30
−
0
View file @
bc360fdb
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets