1 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 else26 {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; // Kilobyte39 $mb = 1024 * $kb; // Megabyte40 $gb = 1024 * $mb; // Gigabyte41 $tb = 1024 * $gb; // Terabyte42 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 else60 {61 return round($size/$tb,2)." TB";62 }63 64 }