note 25961 deleted from function.filesize by tomsommer

From: Date: Wed, 01 Sep 2004 17:33:42 +0000
Subject: note 25961 deleted from function.filesize by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75883@lists.php.net to get a copy of this message
Note Submitter: PHPMatrix ---- I found this nice little human readable file size code. It seems simpler and easier to understand. I'm a PHP newbee so that's why I say its easy to understand. I don't get the above codes, lol. Hope it helps some other newbe, lol. <?php $my_file = "/path/to/my/file"; $file_size = filesize($my_file); if ($file_size >= 1073741824) { $show_filesize = number_format(($file_size / 1073741824),2) . " GB"; } elseif ($file_size >= 1048576) { $show_filesize = number_format(($file_size / 1048576),2) . " MB"; } elseif ($file_size >= 1024) { $show_filesize = number_format(($file_size / 1024),2) . " KB"; } elseif ($file_size >= 0) { $show_filesize = $file_size . " bytes"; } else { $show_filesize = "0 bytes"; } echo "File $my_file is $show_filesize "; ?> Ryan

« previous php.notes (#75883) next »