| | string $iconClass, |
| | int $timestamp, |
| | - string $size = '' |
| | + int $size = 0 |
| | ): void; |
| | |
| | public function renderTime( int $timestamp ): void; |
| | + |
| | + public function renderSize( int $bytes ): void; |
| | } |
| | |
 |
| | string $iconClass, |
| | int $timestamp, |
| | - string $size = '' |
| | + int $size = 0 |
| | ): void { |
| | $fullPath = ($this->currentPath===''?'':$this->currentPath.'/') . $name; |
 |
| | echo '</span>'; |
| | |
| | - if( $size ) { |
| | - echo '<span class="file-size">' . $size . '</span>'; |
| | + if( $size > 0 ) { |
| | + echo '<span class="file-size">' . $this->formatSize($size) . '</span>'; |
| | } |
| | |
 |
| | |
| | echo 'just now'; |
| | + } |
| | + |
| | + public function renderSize( int $bytes ): void { |
| | + echo $this->formatSize($bytes); |
| | + } |
| | + |
| | + private function formatSize( int $bytes ): string { |
| | + if( $bytes === 0 ) { |
| | + return '0 B'; |
| | + } |
| | + |
| | + $units = ['B', 'KB', 'MB', 'GB', 'TB']; |
| | + $i = 0; |
| | + |
| | + while( $bytes >= 1024 && $i < count($units) - 1 ) { |
| | + $bytes /= 1024; |
| | + $i++; |
| | + } |
| | + |
| | + return round($bytes, 2) . ' ' . $units[$i]; |
| | } |
| | } |