note 88531 deleted from features.file-upload by thiago

From: Date: Wed, 28 Jan 2009 11:18:30 +0000
Subject: note 88531 deleted from features.file-upload by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149883@lists.php.net to get a copy of this message
Note Submitter: info at levaravel dot com ---- Here is a function I wrote for file uploads, which returns the filesize in a standard format: <?php // function display_filesize($filesize){ if(is_numeric($filesize)){ $decr = 1024; $step = 0; $ext = array('Byte','KB','MB','GB','TB','PB'); while(($filesize / $decr) > 0.9){ $filesize = $filesize / $decr; $step++; } return round($filesize,2).' '.$ext[$step]; } else { return 'NaN'; } } // Usage: // display_filesize(int number); echo display_filesize(1263541); // writes: 1.21 MB echo display_filesize(1000000000); // writes: 0.93 GB echo display_filesize('stringvalue'); // writes: NaN ?>

« previous php.notes (#149883) next »