| AND OR | string words | *

directories

|

human readable size

| see demonstration of human readable size


to give a user the size of his account (or the admin the size of the users folder)
in a more human readable format, you can use this

it will return the value in megabytes so its more easy to read.


function dirsize( ) [ line 2 ]


function format_size( ) [ line 27 ]



full source of human readable size [ line 1 - 44 ] | download human readable size

1    <?
2   function dirsize($directory
3   {
4       if (!is_dir($directory)) return -1;
5       $size 0;
6       if ($DIR opendir($directory)) 
7       {
8           while (($dirfile readdir($DIR)) !== false
9           {
10               if (is_link($directory '/' $dirfile) || $dirfile == '.' || $dirfile == '..'
11                   continue;
12               if (is_file($directory '/' $dirfile)) 
13                   $size += filesize($directory '/' $dirfile);
14               else if (is_dir($directory '/' $dirfile)) 
15               {
16                   $dirSize dirsize($directory '/' $dirfile); 
17                   if ($dirSize >= 0$size += $dirSize
18                   else return -1;
19               }
20           }
21           closedir($DIR);
22       }
23       return $size;
24   }
25   // stolen from another fine user on php.net 
26   // 
27   function format_size($rawSize
28   {
29       if ($rawSize 1048576 1
30           return round($rawSize/10485761) . 'MB'
31       else if ($rawSize 1024 1
32           return round($rawSize/10241) . 'KB'
33       else 
34           return round($rawSize1) . 'bytes';
35   }
36   $dir '.';
37   $size dirsize($dir);
38   if ($size 0)
39   {
40       echo '<p>ERROR! Bad path "'.$dir.'" !'
41   }else{
42       echo '<p>the '.$dir.' folder is ' format_size($size);
43   }
44   ?> 
45   



26 hits by 18 users in the last 30 minutes.