function usedSpace($curProjId = NULL, $company_id = SES_COMP) { App::import('Model', 'CaseFile'); $CaseFile = new CaseFile(); $CaseFile->recursive = -1; $cond = " 1 "; if ($company_id) { $cond .= " AND company_id=" . $company_id; } if ($curProjId) { $cond .= " AND project_id=" . $curProjId; } $sql = "SELECT SUM(file_size) AS file_size FROM case_files WHERE " . $cond; $res1 = $CaseFile->query($sql); $filesize = $res1['0']['0']['file_size'] / 1024; return number_format($filesize, 2); }