Skip to content

Commit

Permalink
Add Last Modified and Size to files and folders list. Size of folders…
Browse files Browse the repository at this point in the history
… is calculated recursively
  • Loading branch information
Isaac Connor committed Nov 10, 2024
1 parent 3c6ba77 commit 1667e97
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions web/skins/classic/views/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,35 @@ function guess_material_icon($file) {
<tr>
<th class="colSelect"><input type="checkbox" name="toggleCheck" value="1" data-checkbox-name="files[]" data-on-click-this="updateFormCheckboxesByName"></th>
<th class="colName"><?php echo translate('Filename') ?></th>
<th class="colMtime"><?php echo translate('Last Modified') ?></th>
<th class="colSize"><?php echo translate('Size') ?></th>
</tr>
</thead>
<tbody>
<?php
function get_dir_size($dir_path) {
$size = 0;
$entries = is_readable($dir_path) ? scandir($dir_path) : array();
foreach ($entries as $file) {
if ($file == '.' || $file == '..') {
continue;
}
$full_path = $dir_path.'/'.$file;
if (@is_file($full_path)) {
$stat = stat($full_path);
if (!$stat) {
ZM\Error("Fail to stat $full_path");
continue;
}
$size += $stat[7];
} else if (@is_dir($full_path)) {
$size += get_dir_size($full_path);
}
} # end foreach
return $size;
} # end function get_dir_size


if ($path) {
$entries = is_readable($path) ? scandir($path) : array();
foreach ($entries as $file) {
Expand Down Expand Up @@ -139,17 +164,25 @@ function guess_material_icon($file) {
</tr>';
}
foreach ($folders as $folder) {
$url = urlencode(($path?$path.'/':'').$folder);
$full_path = ($path?$path.'/':'').$folder;
$url = urlencode($full_path);
$stat = stat($full_path);
echo '
<tr>
<td class="colSelect"><input type="checkbox" name="files[]" value="'.validHtmlStr($folder).'"/></td>
<td><span class="material-icons md-18">folder</span><a href="?view=files&amp;path='.$url.'">'.validHtmlStr($folder).'</a></td>
<td class="colMtime">'.$dateTimeFormatter->format($stat[9]).'</td>
<td class="colSize">'.human_filesize(get_dir_size($full_path)).'</td>
</tr>';
}
foreach ($files as $file) {
$url = urlencode($path.'/'.$file);
$full_path = ($path?$path.'/':'').$file;
$url = urlencode($full_path);
$stat = stat($full_path);
echo '<tr><td class="colSelect"><input type="checkbox" name="files[]" value="'.validHtmlStr($file).'"/></td>
<td><span class="material-icons md-18">'.guess_material_icon($file).'</span><a href="?view=files&amp;path='.$url.'">'.validHtmlStr($file).'</a></td>
<td class="colMtime">'.$dateTimeFormatter->format($stat[9]).'</td>
<td class="colSize">'.human_filesize($stat[7]).'</td>
</tr>';
}

Expand Down

0 comments on commit 1667e97

Please sign in to comment.