You are here:Home arrow Home arrow PHP arrow Function to format filesize
  • Narrow screen resolution
  • Wide screen resolution
  • Decrease font size
  • Default font size
  • Increase font size
  • default color
  • green color
  • blue color

Function to format filesize

Monday, 27 December 2010
This lightweight function will display file size in a user friendly format without much effort. I.e.: // will output i.e. 1KB (function always accepts bytes value)
echo convert(1024);
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
Get peak memory usage: die(var_dump(convert(memory_get_peak_usage(true))));




Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!
Last Updated ( Monday, 27 December 2010 )

Add comment


Security code
Refresh

Next >