Hi guys,
First of, I love Couch - Thank you so much for all the hard time and work you put in to this, bless!
I been trying to come up with a way to display the file size (In a formatted way) of uploaded files that I want to display on a page. This is the solution I came up with, maybe it's clunky but it works
Happy Friday
First of, I love Couch - Thank you so much for all the hard time and work you put in to this, bless!
I been trying to come up with a way to display the file size (In a formatted way) of uploaded files that I want to display on a page. This is the solution I came up with, maybe it's clunky but it works

- Code: Select all
<?php
function filesize_formatted($path)
{
$path = preg_replace("!^htt.*/folder/!imsU","/var/www/yourdomain.com/folder/",$path);
$size = filesize($path);
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
}
?>
<cms:php>
$name = pathinfo('<cms:show file />')['filename'];
$fullname = '<cms:show file />';
$ext = pathinfo('<cms:show file />')['extension'];
echo "<span class=\"fileinfo\">$ext </span>File | ".filesize_formatted("$fullname");
</cms:php>
Happy Friday
