That just formats the size in a string to something human readable.
To get the actual size of file you need this one instead…
<?= F::size($item->locfile()->toFile()) ?>
If you stored that in a variable instead of echoing it, you could run it through niceSize to get into something more readable instead of a string of numbers.
Thanks.
Using blueprints in the panel, I upload a pdf file.
I add it to a field and give it a name in another field.
I get locfile and locname via
‘items’ => $page->locfilelist1()->toStructure()
but variant F::size($item->locfile()->toFile()) returns 0, not null
$items = $page->locfilelist1()->toStructure();
foreach ( $items as $item ) :
if ( $file = $item->locfile()->toFile() ) :
// now you have a file object
echo $file->url();
echo $file->niceSize();
endif;
endforeach;
Friends, tell me.
Is it possible to insert magic letters or numbers into these niceSize () brackets, so that it would turn out as in the screenshot.
Thank you very much.
Hi @texnixe and @obrsk did you ever cook up a solution for a nicerSize() method that you are willing to share? I’m after the same thing: rounded filesizes without decimals…
This is the overwritten method, the only change to the original niceSize() method is the 2nd parameter passed to the round() function. You can even make this a parameter to make it more versatile.
Do you also need to overwrite the units like Mark?
I just returned here to post my solution only to find out about your reply (strangely enough I had not received any notification…)
Although the rounding part is pretty much identical, my approach consisted of a rather cobbled together function that I used on the raw byte output instead of this elegant file method. Just like you suggested, I had actually added the rounding precision as a parameter (0 as default).
Your support is nothing short of amazing texnixe, many thanks for this!