note 77518 deleted from function.filesize by aidan

From: Date: Sat, 02 May 2009 11:16:54 +0000
Subject: note 77518 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154117@lists.php.net to get a copy of this message
Note Submitter: trask768 at yahoo dot com ---- Updated function to return human readable file size: <?php function size_readable ($size, $retstring = null) { // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if ($retstring === null) { $retstring = '%01.2f %s'; } $lastsizestring = end($sizes); foreach ($sizes as $sizestring) { if ($size < 1024) { break; } if ($sizestring != $lastsizestring) { $size /= 1024; } } if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional return sprintf($retstring, $size, $sizestring); } ?>

« previous php.notes (#154117) next »