/htdocs/core/class/datatables/filters/Filesize.php

https://bitbucket.org/speedealing/speedealing · PHP · 26 lines · 16 code · 8 blank · 2 comment · 1 complexity · 54fcf64d023852ec18501a71b188728c MD5 · raw file

  1. <?php
  2. namespace datatables\filters;
  3. use datatables\FilterInterface;
  4. class Filesize implements FilterInterface {
  5. protected $precision;
  6. /* ______________________________________________________________________ */
  7. public function __construct($precision = 2) {
  8. $this->precision = $precision;
  9. }
  10. /* ______________________________________________________________________ */
  11. public function apply($input) {
  12. $sizes = array(' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB');
  13. if($input) {
  14. return (round($input/pow(1024, ($n = floor(log($input, 1024)))), $this->precision) . $sizes[$n]);
  15. }
  16. return '&mdash;';
  17. }
  18. }