note 17017 added to function.filesize

From: Date: Thu, 22 Nov 2001 11:14:47 +0000
Subject: note 17017 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-21153@lists.php.net to get a copy of this message
To solve the 1000/1024 multipliers problems, I suggest to use the IEC (International Electrotechnical Commission) prefixes (see http://www.technick.net/guide_tables_prefix.php at the end of page) Note that b=bit and B=byte. Take a look at the examples below: // ------------------------------------------------------------ // return size (in bytes) rounded to 2 decimals and using IEC prefixes // see: http://www.technick.net/guide_tables_prefix.php // ------------------------------------------------------------ function formatIECByteSize($size) { $exp = 0; while($size >= pow(1024,($exp+1))) {$exp++;} $ext=array("B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"); $newsize = round($size/pow(1024,$exp),2); $newsize .= $ext[$exp]; //attach IEC prefix return ($newsize); } // ------------------------------------------------------------ // return size (in bytes) rounded to 2 decimals and using SI prefixes // see: http://www.technick.net/guide_tables_prefix.php // ------------------------------------------------------------ function formatSIByteSize($size) { $exp = 0; while($size >= pow(1000,($exp+1))) {$exp++;} $ext=array("B","kB","MB","GB","TB","PB","EB","ZB","YB"); $newsize = round($size/pow(1000,$exp),2); $newsize .= $ext[$exp]; //attach SI prefix return ($newsize); } ---------------------- Sincerely, Nicola Asuni www.technick.net -- http://www.php.net/manual/en/function.filesize.php http://master.php.net/manage/user-notes.php?action=edit+17017 http://master.php.net/manage/user-notes.php?action=delete+17017 http://master.php.net/manage/user-notes.php?action=reject+17017

« previous php.notes (#21153) next »