Project Introduction
In this chapter, we build a File Manager module - a complete, database-backed admin interface for managing uploaded files. Users can upload files, browse the file list with pagination and search, view file metadata, download files, and delete them with confirmation.
This chapter applies everything you learned in the Basic CRUD chapter - the admin manage page pattern, pagination, search, confirm-and-delete - and introduces file uploads as a real-world extension. By the end, you will have a reusable file manager that you can drop into any Trongate project.
Want the complete code? Grab the full example from GitHub:
https://github.com/grady-trongate/Trongate-v2-File-Manager
This repository contains the finished file_manager module (controller, model, and four views), a file_manager.sql file with the schema and sample data, and a README with quick-start instructions.
What Is Different About This Chapter?
The Trongate framework documentation already covers the File module's individual methods in depth - how $this->file->upload() works, what configuration keys it accepts, how file paths are constructed, and so on. This chapter does not repeat that reference material. Instead, it shows you how to assemble those methods into a working admin module, complete with a database index, a proper CRUD interface, and practical file operations like download and filesystem deletion.
Methods We Will Build
| URL | Method | Purpose |
|---|---|---|
/file_manager/manage |
manage() |
Paginated list of uploaded files |
/file_manager/create |
create() |
Upload form |
/file_manager/submit |
submit() |
Process upload with validation |
/file_manager/show/{id} |
show() |
View file metadata |
/file_manager/download/{id} |
download() |
Download the file |
/file_manager/confirm_delete/{id} |
confirm_delete() |
Delete confirmation page |
/file_manager/submit_confirm_delete |
submit_confirm_delete() |
Process deletion |
What You Will Learn
- Uploading files to a module directory with random filenames
- Storing file metadata in a database table alongside the uploaded file
- Listing files with pagination, search, and human-readable file sizes
- Serving files for download via a controller method
- Deleting files from both the database and the filesystem
- Integrating the File module with the admin CRUD pattern
Let us begin by setting up the database table.
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.