Human readable file size

This function return formatting of file sizes in a human readable format.

function formatFileSize( $size )
{
   $file_size = $size;
   $i = 0;
 
   $name = array( 'byte', 'kB', 'MB', 'GB' );
 
   while ( $file_size > 1000 ) {
      $i++;
      $file_size = $file_size / 1024;
   }
 
   return round( $file_size, 2 ) . " " . $name[$i];
 
}
 
echo formatFileSize( 1024 * 1024 ); //out = 1 MB

Tags

No tag here.

Recommended pages

SQL escape string function...

Escapes special characters in a string for use in an SQL statement. howewer it check get_magic_quotes_gpc function is enable or no. if true , it strips string from slashes and escaped string from spec...

File size calculator...

File size calculator function return file size format into kb, mb or gb. function file_size($size, $out = 'kb', $precision = 2) { switch ($out) { case 'kb': return round($...

How to created mixed arguments function...

This way useful for create mixed arguments function. function foo() { $args = func_get_args(); print_r($args); }   foo(1, 1256, 6, 17); //mixed ...   -------------------Out-...

Gregorian to Persian Date Convertor...

Gregorian to Persian Date Convertor....