/htdocs/core/class/datatables/filters/Filesize.php
PHP | 26 lines | 16 code | 8 blank | 2 comment | 1 complexity | 54fcf64d023852ec18501a71b188728c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
- <?php
- namespace datatables\filters;
- use datatables\FilterInterface;
- class Filesize implements FilterInterface {
-
- protected $precision;
-
- /* ______________________________________________________________________ */
-
- public function __construct($precision = 2) {
- $this->precision = $precision;
- }
-
- /* ______________________________________________________________________ */
-
- public function apply($input) {
- $sizes = array(' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB');
- if($input) {
- return (round($input/pow(1024, ($n = floor(log($input, 1024)))), $this->precision) . $sizes[$n]);
- }
- return '—';
- }
- }