Function to get Size of Files in b,kb,mb,gb
 
I found this pretty cool function which I used for the knowledgebase myself. It atomatically gets the size of your files, adding the b, kb, mb and gb at the end:

<?php
function filesize_h($size, $dec = 1)
{
$sizes = array('B', 'KB', 'MB', 'GB');
$count = count($sizes);
$i = 0;
while ($size >= 1024 && ($i < $count - 1))
{
$size /= 1024;
$i++;
}
return round($size, $dec) . ' ' . $sizes[$i];
}
?>


Example:

<?php
require_once 'function.filesize_h.php';
echo filesize_h(34);
echo "n";
echo filesize_h(3224);
echo "n";
echo filesize_h(2342343, 2);
echo "n";
echo filesize_h(242342322);
echo "n";
echo filesize_h(322423423424);
?>



Output:
34 B
3.1 KB
2.23 MB
231.1 MB
300.3 GB




Source: http://aidan.dotgeek.org/lib/?file=function.filesize_h.php
 
admin / Oct 31, 2003
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch