954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Function to format bytes in human readable format

0
By jhbalaji on May 11th, 2010 8:25 pm

I was digging through my old codes to get this, still could not find. Hence when I wrote it, just made a note here such that later it wont be difficult to find atleast for me.

Format filesize, php filesize human readable

function formatSize($size){
     $units = array(' B', ' KB', ' MB', ' GB', ' TB');
     for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
     return round($size, 2).$units[$i];
 }

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You