Listing Files
The manage() method displays a paginated table of uploaded files, with search, action buttons, and the standard admin pagination. It follows the same pattern as the manage() method from the Basic CRUD chapter.
The Controller Method
public function manage(): void {
$this->gatekeeper();
$search_query = $_GET['search_query'] ?? '';
$search_column = $_GET['search_column'] ?? '';
$limit = $this->get_limit();
$offset = $this->get_offset();
$rows = $this->model->get_all_files(
$limit, $offset,
$search_query, $search_column
);
$total = $this->model->count_all_files(
$search_query, $search_column
);
$data['rows'] = $rows;
$data['total'] = $total;
$data['limit'] = $limit;
$data['offset'] = $offset;
$data['search_query'] = $search_query;
$data['search_column'] = $search_column;
$data['num_rows'] = count($rows);
$data['view_module'] = 'file_manager';
$data['view_file'] = 'manage';
$this->templates->admin($data);
}The View File
<div class="container">
<h1>File Manager</h1>
<p>
<a href="<?= BASE_URL ?>file_manager/create"
class="btn btn-primary">
<i class="fa-solid fa-upload"></i>
Upload New File
</a>
</p>
<?php
$pagination_data = [
'num_rows' => $num_rows,
'total' => $total,
'limit' => $limit,
'offset' => $offset,
'search_query' => $search_query,
'search_column' => $search_column
];
echo $this->pagination->admin_pagination(
$pagination_data
);
?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Document Name</th>
<th>File Name</th>
<th>File Size</th>
<th>Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (
$rows && count($rows) > 0
): ?>
<?php foreach ($rows as $row): ?>
<tr>
<td>
<?= out($row->doc_name) ?>
</td>
<td>
<code>
<?= out($row->file_name) ?>
</code>
</td>
<td>
<?= number_format(
$row->file_size
) ?> bytes
</td>
<td>
<?= out($row->file_type) ?>
</td>
<td>
<a href="<?= BASE_URL ?>
file_manager/show/<?= $row->id ?>"
class="btn btn-default btn-sm">
<i class="fa-solid fa-eye"></i>
View
</a>
<a href="<?= BASE_URL ?>
file_manager/download/<?= $row->id ?>"
class="btn btn-success btn-sm">
<i class="fa-solid fa-download"></i>
Download
</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="5">
No files found.
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>Displaying File Size
File sizes are stored in bytes - the raw value from upload(). In the manage view, we use PHP's number_format() to display the value with thousand separators, making large files readable:
12453→12,453 bytes245600→245,600 bytes
For a more user-friendly display (KB, MB), you could add a simple formatting helper. The key principle, however, is to keep formatting in the view and raw data in the database.
We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.
Share your thoughts in the Documentation Feedback.