Get the size of a file in bytes or MB

I’ve build a small file manager to display on the front-end where each file has the size of the file written right below it. I can call this size with

$file = File::getByID( 1 );
$size = $file->getSize();

However this gives the filesize back in KB’s instead of either MB or GB.

Perfect would be to get the raw filesize in bytes just like how it’s displayed in the filemanager in the backend:

However, I haven’t been able to find which concrete function to use to call this number.

Could somebody help me out or point me in the right direction?

Regards

$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();

$file = File::getByID(1);

// Automatic unit (KB, MB etc.)
echo $app->make('helper/number')->formatSize($file->getFullSize());

// Force unit (MB, GB etc.)
echo $app->make('helper/number')->formatSize($file->getFullSize(), 'MB');

// In bytes
echo $file->getFullSize();

// Check source code in this files:
/concrete/src/Entity/File/Version.php
/concrete/src/Utility/Service/Number.php

Thank you so much for the getFullSize() function, I wasn’t able to find it in the docs. I wasn’t able to get the formatSize() function working so I took one from stackoverflow. But the end result is the same.