note 56030 added to function.filesize

From: Date: Sun, 21 Aug 2005 10:08:27 +0000
Subject: note 56030 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-93980@lists.php.net to get a copy of this message
Heres the function i made. <?php // Function function size_translate($filesize) { $array = array( 'YB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'ZB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'EB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'PB' => 1024 * 1024 * 1024 * 1024 * 1024, 'TB' => 1024 * 1024 * 1024 * 1024, 'GB' => 1024 * 1024 * 1024, 'MB' => 1024 * 1024, 'KB' => 1024, ); if($filesize <= 1024) { $filesize = $filesize . ' Bytes'; } foreach($array AS $name => $size) { if($filesize > $size || $filesize == $size) { $filesize = round((round($filesize / $size * 100) / 100), 2) . ' ' . $name; } } return $filesize; } // Example echo size_translate(1024 * 1024 * 1024 * 1024 * 1024 * 4.95); // Returns: 4.95 Petabytes ?> Btw, you guys need to learn how to code clean. ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56030 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56030&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56030&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93980) next »