Пример #1
0
function recursive_directory_size($directory, $format = FALSE)
{
    $size = 0;
    if (substr($directory, -1) == '/') {
        $directory = substr($directory, 0, -1);
    }
    if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
        return -1;
    }
    if ($handle = opendir($directory)) {
        while (($file = readdir($handle)) !== false) {
            $path = $directory . '/' . $file;
            if ($file != '.' && $file != '..') {
                if (is_file($path)) {
                    $size += filesize($path);
                } elseif (is_dir($path)) {
                    $handlesize = recursive_directory_size($path);
                    if ($handlesize >= 0) {
                        $size += $handlesize;
                    } else {
                        return -1;
                    }
                }
            }
        }
        closedir($handle);
    }
    if ($format == TRUE) {
        return formatfilesize($size);
    } else {
        return $size;
    }
}
Пример #2
0
echo __("Database size:", $module);
?>
</dt>
			<dd><?php 
echo formatfilesize($this->administration->db_size());
?>
</dd>
			<dt>C<?php 
echo __("Cache size:", $module);
?>
 <?php 
echo anchor('admin/clear_cache', __("Clear", $module));
?>
</dt>
			<dd><?php 
echo recursive_directory_size($this->config->item('cache_path'), TRUE);
?>
</dd>
		</dl>
	</div>
	
	<div class="right">
		<h2><?php 
echo __("Latest News", $module);
?>
</h2>
		<ul>
			<?php 
$i = 0;
if (CICMS_VERSION < $latest_version) {
    $k = 8;
Пример #3
0
/**
 * Find the size of a directory, including any subdirectories
 *
 * @param string $directory Directory
 * @param boolean $format Format
 * @return array Size/number of files
 */
function recursive_directory_size($directory, $format = FALSE)
{
    $size = 0;
    $files = 0;
    /* If the path has a slash at the end we remove it here */
    if (substr($directory, -1) == '/') {
        $directory = substr($directory, 0, -1);
    }
    /* If the path is not valid or is not a directory ... */
    if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
        /* ... We return -1 and exit the function */
        return -1;
    }
    /* We open the directory */
    if ($handle = opendir($directory)) {
        /* And scan through the items inside */
        while (($file = readdir($handle)) !== false) {
            /* We build the new path */
            $path = $directory . '/' . $file;
            /* If the filepointer is not the current directory or the parent directory */
            if ($file != '.' && $file != '..') {
                /* If the new path is a file */
                if (is_file($path)) {
                    /* We add the filesize to the total size */
                    $size += filesize($path);
                    $files++;
                    /* If the new path is a directory */
                } elseif (is_dir($path)) {
                    /* If $format is set to true, follow the directory and recalculate from there */
                    if ($format) {
                        /* We call this function with the new path */
                        $handlesize = recursive_directory_size($path);
                        if (is_int($handlesize)) {
                            /* If the function returns more than zero */
                            if ($handlesize >= 0) {
                                /* We add the result to the total size */
                                $size += $handlesize;
                                /* Else we return -1 and exit the function */
                            } else {
                                return -1;
                            }
                            /* Else we return -1 and exit the function */
                        } else {
                            return -1;
                        }
                    }
                }
            }
        }
        /* Close the directory */
        closedir($handle);
    }
    /* Return the total filesize in bytes */
    return array($size, $files);
}
Пример #4
0
 function spaceused()
 {
     global $tc_db, $tpl_page;
     $this->AdministratorsOnly();
     $tpl_page .= '<h2>' . _gettext('Disk space used') . '</h2><br />';
     $spaceused_res = 0;
     $spaceused_src = 0;
     $spaceused_thumb = 0;
     $spaceused_total = 0;
     $files_res = 0;
     $files_src = 0;
     $files_thumb = 0;
     $files_total = 0;
     $tpl_page .= '<table border="1" width="100%"><tr><th>' . _gettext('Board') . '</th><th>' . _gettext('Area') . '</th><th>' . _gettext('Files') . '</th><th>' . _gettext('Space Used') . '</th></tr>';
     $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `name` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
     foreach ($results as $line) {
         list($spaceused_board_res, $files_board_res) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/res');
         list($spaceused_board_src, $files_board_src) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/src');
         list($spaceused_board_thumb, $files_board_thumb) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/thumb');
         $spaceused_board_total = $spaceused_board_res + $spaceused_board_src + $spaceused_board_thumb;
         $files_board_total = $files_board_res + $files_board_src + $files_board_thumb;
         $spaceused_res += $spaceused_board_res;
         $files_res += $files_board_res;
         $spaceused_src += $spaceused_board_src;
         $files_src += $files_board_src;
         $spaceused_thumb += $spaceused_board_thumb;
         $files_thumb += $files_board_thumb;
         $spaceused_total += $spaceused_board_total;
         $files_total += $files_board_total;
         $tpl_page .= '<tr><td rowspan="4">/' . $line['name'] . '/</td><td>res/</td><td>' . number_format($files_board_res) . '</td><td>' . ConvertBytes($spaceused_board_res) . '</td></tr>';
         $tpl_page .= '<tr><td>src/</td><td>' . number_format($files_board_src) . '</td><td>' . ConvertBytes($spaceused_board_src) . '</td></tr>';
         $tpl_page .= '<tr><td>thumb/</td><td>' . number_format($files_board_thumb) . '</td><td>' . ConvertBytes($spaceused_board_thumb) . '</td></tr>';
         $tpl_page .= '<tr><td><strong>' . _gettext('Total') . '</strong></td><td>' . number_format($files_board_total) . '</td><td>' . ConvertBytes($spaceused_board_total) . '</td></tr>';
     }
     $tpl_page .= '<tr><td rowspan="4"><strong>' . _gettext('All boards') . '</strong></td><td>res/</td><td>' . number_format($files_res) . '</td><td>' . ConvertBytes($spaceused_res) . '</td></tr>';
     $tpl_page .= '<tr><td>src/</td><td>' . number_format($files_src) . '</td><td>' . ConvertBytes($spaceused_src) . '</td></tr>';
     $tpl_page .= '<tr><td>thumb/</td><td>' . number_format($files_thumb) . '</td><td>' . ConvertBytes($spaceused_thumb) . '</td></tr>';
     $tpl_page .= '<tr><td><strong>' . _gettext('Total') . '</strong></td><td>' . number_format($files_total) . '</td><td>' . ConvertBytes($spaceused_total) . '</td></tr>';
     $tpl_page .= '</table>';
     management_addlogentry(_gettext('Viewed disk space used'), 0);
 }