note 25961 added to function.filesize
| From: | PHPMatrix at rack1 dot php dot net | Date: | Sat, 12 Oct 2002 22:25:53 +0000 |
| Subject: | note 25961 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37990@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/function.filesize.php
http://master.php.net/manage/user-notes.php?action=edit+25961
http://master.php.net/manage/user-notes.php?action=delete+25961
http://master.php.net/manage/user-notes.php?action=reject+25961