1 <?php
 2 public function statistics()
 3     {
 4         $space = $_SESSION ['spaceSize'];
 5         $id = $_SESSION[C ( 'USER_AUTH_KEY' )];
 6         echo $id;
 7         $neicun = $this->getRealSize($this->getDirSize(dirname($_SERVER['SCRIPT_FILENAME']).'/Public/Editor/attached/image/'.$id));
 8         $message = '我是系统消息';
 9         $this->assign('neicun', $neicun);
10         $this->assign('space', $space);
11         $this->assign('sysmessage', $message);
12         $this->display();
13     }
14     public function getDirSize($dir)
15     {
16         $handle = opendir($dir);
17         while (false!==($FolderOrFile = readdir($handle)))
18         {
19             if($FolderOrFile != "." && $FolderOrFile != "..")
20             {
21                 if(is_dir("$dir/$FolderOrFile"))
22                 {
23                     $sizeResult += $this->getDirSize("$dir/$FolderOrFile");
24                 }
25                 else
26                 {
27                     $sizeResult += filesize("$dir/$FolderOrFile");
28                 }
29             }
30         }
31         closedir($handle);
32         return $sizeResult;
33     }
34     
35     // 单位自动转换函数
36     function getRealSize($size)
37     {
38         $kb = 1024;         // Kilobyte
39         $mb = 1024 * $kb;   // Megabyte
40         $gb = 1024 * $mb;   // Gigabyte
41         $tb = 1024 * $gb;   // Terabyte
42     
43         if($size < $kb)
44         {
45             return $size." B";
46         }
47         else if($size < $mb)
48         {
49             return round($size/$kb,2)." KB";
50         }
51         else if($size < $gb)
52         {
53             return round($size/$mb,2)." MB";
54         }
55         else if($size < $tb)
56         {
57             return round($size/$gb,2)." GB";
58         }
59         else
60         {
61             return round($size/$tb,2)." TB";
62         }
63         
64     }


 

posted on 2014-02-24 16:15  GlobeMaya  阅读(420)  评论(0)    收藏  举报