Visitors Today: 152
Total Visits: 435091


Do you have source code, articles, and tutorials to share?
Visual Basic, VB.NET, C#, PHP/MySQL, C/C++, Java/JavaScript, ASP/ASP.NET, MS Access, FoxPro, SQL
You can write your own content here.


    If the information on this site helps you and you would like to make donation to please click the LINK below.

    If you want to support us, please make a contribution. Any amount is appreciated. To make a donation via PayPal, credit card, or e-check..

    Please click the DONATE link..

    Your contribution will make grow in the future.



Smarty Modifier PHP Filesize (bytes to KB/MB)

    Posted GraniteGear Posted On March 5, 2013

    PHP 0 Current Comments 6295 Views

    Like 18 people liked this.
    You want to display the size of the file in Kb if less then 1024, in Mb if less than 1048576 etc... Here's a quick snip of code to help you easily manage your files by finding out the size/size of the file...

    function filesize($size)
     $size = max(0, (int)$size);
     $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];

  • PHP
  • Script
Share With Your Friends
Share Your Thoughts With Other Users

Be the first to comment.

Leave a Reply
This small test serves as access restriction against malicious bots.