note 55019 deleted from function.filesize by aidan

From: Date: Wed, 09 Nov 2005 06:14:24 +0000
Subject: note 55019 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-98293@lists.php.net to get a copy of this message
Note Submitter: ---- An improve of DASPRiD's code from the function to convert bytes into a readable size: <? function filesize_format ($bytes, $decimal='.', $spacer=' ', $lowercase=false) { $bytes = max(0, (int)$bytes); $units = array('YB' => 1208925819614629174706176, // yottabyte 'ZB' => 1180591620717411303424, // zettabyte 'EB' => 1152921504606846976, // exabyte 'PB' => 1125899906842624, // petabyte 'TB' => 1099511627776, // terabyte 'GB' => 1073741824, // gigabyte 'MB' => 1048576, // megabyte 'KB' => 1024, // kilobyte 'B' => 0); // byte foreach ($units as $unit => $qty) { if ($bytes >= $qty) return number_format(!$qty ? $bytes: $bytes /= $qty, 2, $decimal, $spacer).$spacer.$unit; } } // end of 'filesize_format' function(); ?> For example: INPUT: 1169 OUTPUT: 1.14 KB

« previous php.notes (#98293) next »