note 80290 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Sat, 02 May 2009 11:16:33 +0000 |
| Subject: | note 80290 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154115@lists.php.net to get a copy of this message | ||
Note Submitter: marcel at marcel-hergerdt dot de
----
This script checks whether the file is large enough for the next unit and calculates them.
Example:
29249 bytes => 28.56 KB
10083695 bytes => 9.62 MB
<?php
function get_size($size) {
$bytes = array('B','KB','MB','GB','TB');
foreach($bytes as $val) {
if($size > 1024){
$size = $size / 1024;
}else{
break;
}
}
return round($size, 2)." ".$val;
}
?>