Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Feature to Display Disk Space Usage #1100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion tinyfilemanager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
//Default Configuration
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light","show_disk_usage":true}';

/**
* H3K | Tiny File Manager V2.5.3
Expand Down Expand Up @@ -196,6 +196,8 @@
// Theme
$theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';

$show_disk_usage = isset($cfg->data['show_disk_usage']) ? $cfg->data['show_disk_usage'] : true;

define('FM_THEME', $theme);

//available languages
Expand Down Expand Up @@ -539,6 +541,7 @@ function getClientIP() {
$erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
$shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
$hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
$sdu = isset($_POST['js-show-usage']) && $_POST['js-show-usage'] == "true" ? true : false;
$te3 = $_POST['js-theme-3'];

if ($cfg->data['lang'] != $newLng) {
Expand All @@ -557,6 +560,10 @@ function getClientIP() {
$cfg->data['show_hidden'] = $shf;
$show_hidden_files = $shf;
}
if ($cfg->data['show_disk_usage'] != $sdu) {
$cfg->data['show_disk_usage'] = $sdu;
$show_disk_usage = $sdu;
}
if ($cfg->data['hide_Cols'] != $hco) {
$cfg->data['hide_Cols'] = $hco;
$hide_Cols = $hco;
Expand Down Expand Up @@ -1553,6 +1560,16 @@ function getSelected($l) {
</div>
</div>

<div class="mb-3 row">
<label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowDiskUsage') ?></label>
<div class="col-sm-9">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="js-show-usage" name="js-show-usage" value="true" <?php echo $show_disk_usage ? 'checked' : ''; ?> />
</div>
</div>
</div>


<div class="mb-3 row">
<label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
<div class="col-sm-9">
Expand Down Expand Up @@ -2202,10 +2219,31 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced
</tfoot>
<?php
} else { ?>

<?php
// Check if show_disk_usage is true before getting disk size
if ($show_disk_usage) {
// Get total and free space
$total = disk_total_space(FM_ROOT_PATH.'/'.FM_PATH);
$free = disk_free_space(FM_ROOT_PATH.'/'.FM_PATH);

// Format sizes
$total_size = fm_get_filesize($total);
$free_size = fm_get_filesize($free);
$total_used_size = fm_get_filesize($total - $free);
}
?>
<tfoot>
<tr>
<td class="gray" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' :'7') : (FM_READONLY ? '4' : '5') ?>">
<?php echo lng('FullSize').': <span class="badge text-bg-light border-radius-0">'.fm_get_filesize($all_files_size).'</span>' ?>
<?php
// Check if show_disk_usage is true before displaying disk usage
if ($show_disk_usage) {
echo lng('UsedSpace').': <span class="badge text-bg-light border-radius-0">' .$total_used_size.'</span>';
echo lng('RemainingSpace').': <span class="badge text-bg-light border-radius-0">' .$free_size.'</span>';
}
?>
<?php echo lng('File').': <span class="badge text-bg-light border-radius-0">'.$num_files.'</span>' ?>
<?php echo lng('Folder').': <span class="badge text-bg-light border-radius-0">'.$num_folders.'</span>' ?>
</td>
Expand Down Expand Up @@ -4287,6 +4325,9 @@ function lng($txt) {
$tr['en']['Invalid characters in file or folder name'] = 'Invalid characters in file or folder name';
$tr['en']['Operations with archives are not available'] = 'Operations with archives are not available';
$tr['en']['File or folder with this path already exists'] = 'File or folder with this path already exists';
$tr['en']['RemainingSpace'] = 'Remaining Space';
$tr['en']['UsedSpace'] = 'Used Space';
$tr['en']['ShowDiskUsage'] = 'Show Disk Usage';

$i18n = fm_get_translations($tr);
$tr = $i18n ? $i18n : $tr;
Expand Down
Loading