Skip to content

Commit 42fadb2

Browse files
committed
add humanFilesize() for list view
1 parent b69fb36 commit 42fadb2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/controllers/ItemsController.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ private function getFilesWithInfo($path)
3232
foreach (File::files($path) as $key => $file) {
3333
$file_name = parent::getFileName($file)['short'];
3434
$file_created = filemtime($file);
35-
$file_size = number_format((File::size($file) / 1024), 2, ".", "");
36-
37-
if ($file_size > 1024) {
38-
$file_size = number_format(($file_size / 1024), 2, ".", "") . " Mb";
39-
} else {
40-
$file_size = $file_size . " Kb";
41-
}
35+
$file_size = $this->humanFilesize(File::size($file));
4236

4337
if ($this->isProcessingImages()) {
4438
$file_type = File::mimeType($file);

src/traits/LfmHelpers.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,11 @@ public function error($error_type, $variables = [])
187187
{
188188
return trans('laravel-filemanager::lfm.error-' . $error_type, $variables);
189189
}
190+
191+
public function humanFilesize($bytes, $decimals = 2)
192+
{
193+
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
194+
$factor = floor((strlen($bytes) - 1) / 3);
195+
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
196+
}
190197
}

0 commit comments

Comments
 (0)