note 61166 deleted from function.filesize by derick

From: Date: Thu, 23 Feb 2006 14:23:35 +0000
Subject: note 61166 deleted from function.filesize by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104302@lists.php.net to get a copy of this message
Note Submitter: mazaki at shaw dot ca ---- I've been reading through most of the human readable file size functions and most do the trick, here is my version. <?php function human_size( $bytes, $decimal = '2' ) { if( is_numeric( $bytes ) ) { $position = 0; $units = array( " Bytes", " KB", " MB", " GB", " TB" ); while( $bytes >= 1024 && ( $bytes / 1024 ) >= 1 ) { $bytes /= 1024; $position++; } return round( $bytes, $decimal ) . $units[$position]; } else { return "0 Bytes"; } } ?>

« previous php.notes (#104302) next »