note 51227 deleted from function.filesize by aidan

From: Date: Wed, 13 Jul 2005 03:16:15 +0000
Subject: note 51227 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-91851@lists.php.net to get a copy of this message
Note Submitter: php at meteleskublesku dot cz ---- YET ANOTHER SIZE FORMATTING ROUTINE (double fixed example from cstretton) $prec(ision) is the number of important decimal digits in the output, reccomended 3. <?php function fmtsize($size, $prec) { $size = round(abs($size)); $units = array(0=>" B ", 1=>" kB", 2=>" MB", 3=>" GB", 4=>" TB"); if ($size==0) return str_repeat(" ", $prec)."0$units[0]"; $unit = min(4, floor(log($size)/log(2)/10)); $size = $size*pow(2, -10*$unit); $digi = $prec-1-floor(log($size)/log(10)); $size = round($size*pow(10, $digi))*pow(10, -$digi); while (strlen($size)<=$prec) $size = " $size"; return $size.$units[$unit]; } ?>

« previous php.notes (#91851) next »