Skip to content

Commit

Permalink
fix file size calculation (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat authored Mar 9, 2022
1 parent f21eac4 commit cd0973b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upgrade Notes

## Version 4.0.4
- [BUGFIX] fix file size calculation

## Version 4.0.3
- [BUGFIX] return correct default value if editable is null

Expand Down
6 changes: 2 additions & 4 deletions src/ToolboxBundle/Twig/Extension/DownloadExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ public function getDownloadInfo($download, $showPreviewImage = false, $fileSizeU
*/
public function getOptimizedFileSize($bytes, $precision)
{
$format = '';

if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2);
$format = 'gb';
Expand All @@ -180,10 +178,10 @@ public function getOptimizedFileSize($bytes, $precision)
$format = 'kb';
} elseif ($bytes > 1) {
$format = 'bytes';
} elseif ($bytes == 1) {
} elseif ($bytes === 1) {
$format = 'byte';
} else {
$bytes = '0 bytes';
$format = 'bytes';
}

return round($bytes, $precision) . ' ' . $format;
Expand Down

0 comments on commit cd0973b

Please sign in to comment.