note 55658 deleted from function.filesize by nlopess

From: Date: Wed, 10 Aug 2005 09:05:25 +0000
Subject: note 55658 deleted from function.filesize by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93356@lists.php.net to get a copy of this message
Note Submitter: corychristison at lavacube dot com ---- A slightly easier way to accomplish the use largest unit that sleek has developed would be to do: <?php function format_filesize( $filesize ) { $filesize = (int)$filesize; // ensure $filesize is an integer $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); // define list of units $tot_units = (count($units) - 1); // get the largest unit's 'key' $pass = 0; // set zero, for Bytes while( $filesize >= 1024 ) { // break loop if largest unit has been previously reached if( $pass == $tot_units ) { break; } $filesize /= 1024; $pass++; } return round($filesize, 2) .'&nbsp;'. $units[$pass]; } ?> Thank you for pointing that out sleek.

« previous php.notes (#93356) next »