includes/functions.php
changeset 915 91f4da84966f
parent 909 94c1ff984286
child 953 323c4cd1aa37
equal deleted inserted replaced
914:f808e55fb92a 915:91f4da84966f
  2613   }
  2613   }
  2614   else
  2614   else
  2615   {
  2615   {
  2616     return $num;
  2616     return $num;
  2617   }
  2617   }
       
  2618 }
       
  2619 
       
  2620 /**
       
  2621  * Converts a number to a human file size.
       
  2622  * @param int File size
       
  2623  * @return string
       
  2624  */
       
  2625 
       
  2626 function humanize_filesize($size)
       
  2627 {
       
  2628   global $lang;
       
  2629   
       
  2630   if ( $size > ( 1099511627776 * 0.9 ) )
       
  2631   {
       
  2632     return number_format($size / 1099511627776, 1) . $lang->get('etc_unit_terabytes_short');
       
  2633   }
       
  2634   if ( $size > ( 1073741824 * 0.9 ) )
       
  2635   {
       
  2636     return number_format($size / 1073741824, 1) . $lang->get('etc_unit_gigabytes_short');
       
  2637   }
       
  2638   if ( $size > ( 1048576 * 0.9 ) )
       
  2639   {
       
  2640     return number_format($size / 1048576, 1) . $lang->get('etc_unit_megabytes_short');
       
  2641   }
       
  2642   if ( $size > ( 1024 * 0.9 ) )
       
  2643   {
       
  2644     return number_format($size / 1024, 1) . $lang->get('etc_unit_kilobytes_short');
       
  2645   }
       
  2646   return "$size " . $lang->get('etc_unit_bytes');
  2618 }
  2647 }
  2619 
  2648 
  2620 /**
  2649 /**
  2621  * Injects a string into another string at the specified position.
  2650  * Injects a string into another string at the specified position.
  2622  * @param string The haystack
  2651  * @param string The haystack