Format File Size





9
Date Submitted Mon. Oct. 10th, 2005 10:25 AM
Revision 1 of 1
Coder mattrmiller
Tags File | PHP | Size
Comments 3 comments
Get File Size
<?php
        function GetFileSize($nBytes)
        {
                if ($nBytes >= pow(2,40))
                {
                        $strReturn = round($nBytes / pow(1024,4), 2);
                        $strSuffix = "TB";
                }
                elseif ($nBytes >= pow(2,30))
                {
                        $strReturn = round($nBytes / pow(1024,3), 2);
                        $strSuffix = "GB";
                }
                elseif ($nBytes >= pow(2,20))
                {
                        $strReturn = round($nBytes / pow(1024,2), 2);
                        $strSuffix = "MB";
                }
                elseif ($nBytes >= pow(2,10))
                {
                        $strReturn = round($nBytes / pow(1024,1), 2);
                        $strSuffix = "KB";
                }
                else
                {
                        $strReturn = $nBytes;
                        $strSuffix = "Byte";
                }
               
                if ($strReturn == 1)
                {
                        $strReturn .= " " . $strSuffix;
                }
                else
                {
                        $strReturn .= " " . $strSuffix . "s";
                }
               
                return $strReturn;
        }
?>

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

Comments I Like It
Sat. Mar. 11th, 2006 5:20 PM    Helper Scriptsentials
Comments Good Idea
Wed. Feb. 15th, 2006 9:43 PM    Coder mattrmiller
Comments Bad title
Wed. Feb. 15th, 2006 6:54 PM    Newbie adam

Voting