]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
moved formatBytes() to /include/text.php
[friendica.git] / include / text.php
index 5c6ab588f1ba2b4cb011bd575622eaaf5afcdb1f..829e37c2ce97f8088bbd1e2a480454ff681f7c8d 100644 (file)
@@ -2282,3 +2282,15 @@ function deindent($text, $chr="[\t ]", $count=NULL) {
 
        return implode("\n", $lines);
 }
+
+function formatBytes($bytes, $precision = 2) { 
+        $units = array('B', 'KB', 'MB', 'GB', 'TB'); 
+
+       $bytes = max($bytes, 0); 
+       $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); 
+       $pow = min($pow, count($units) - 1); 
+
+       $bytes /= pow(1024, $pow);
+
+       return round($bytes, $precision) . ' ' . $units[$pow]; 
+}