Home > Code Snippets, PHP, Tips > Function to format bytes in human readable format

Function to format bytes in human readable format

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.

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

format filesize, php filesize human readable

Categories: Code Snippets, PHP, Tips Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

twenty one + = twenty two