// BEGIN: borrowed and modified from http://de3.php.net/manual/en/function.filesize.php function size_translate($filesize) { $array = array( 'TiB' => 1024 * 1024 * 1024 * 1024, 'GiB' => 1024 * 1024 * 1024, 'MiB' => 1024 * 1024, 'KiB' => 1024, ); if($filesize <= 1024) { return $filesize . ' B'; } foreach ($array as $name=>$size) { if($filesize >= $size) { return round((round($filesize / $size * 100) / 100), 2) . ' ' . $name; } } return false; } // END: borrowed and modified from http://de3.php.net/manual/en/function.filesize.php
echo size_translate(10559006985);
will show:
9.83 GiB
// BEGIN: borrowed and modified from http://de3.php.net/manual/en/function.filesize.php static function time_translate($seconds) { $array = array( 'y' => 60 * 60 * 24 * 365.25, 'M' => 60 * 60 * 24 * 30.5, 'w' => 60 * 60 * 24 * 7, 'd' => 60 * 60 * 24, 'h' => 60 * 60, 'm' => 60, 's' => 1, ); foreach ($array as $name=>$secs) { if ($seconds < $secs && $secs != end($array)) continue; $resv = floor($seconds / $secs); $res .= ' ' . $resv . $name; $seconds -= $resv*$secs; } return trim($res); } // END: borrowed and modified from http://de3.php.net/manual/en/function.filesize.php
Takes an integer value and returns a string like:
1y 3M 2w 4d 14h 45m 12s