note 55654 deleted from function.filesize by nlopess

From: Date: Wed, 10 Aug 2005 09:05:45 +0000
Subject: note 55654 deleted from function.filesize by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93357@lists.php.net to get a copy of this message
Note Submitter: sleek ---- I altered the function to be a little more flexible. Thanks for the good code <?php function format_filesize($filesize) { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $tot_units = count($units); $pass = 0; // set zero, for Bytes // Keep calculating until we are past the known unit size while ($filesize >= 1024 && $pass <= $tot_units) { $filesize /= 1024; $pass++; } // If we are past the last unit, then make our pass equal the last one if ($pass > $tot_units) { $pass = $tot_units - 1; } return round($filesize, 2).'&nbsp;'.$units[$pass]; } ?>

« previous php.notes (#93357) next »