Introduction
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.
Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.
Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.
Image Uploader Example
Let's walk through building an image uploader using Trongate's upload_picture() method. This example will demonstrate creating a secure image uploader that includes automatic image processing capabilities.
The following example pertains to a hypothetical custom module named as 'products'.
Step 1: Create the Upload Form
Create a view file in your module's views directory:
Step 2: Initialize Picture Settings
Create a method in your controller to define image settings:
Step 3: Create the Upload Handler
Add the upload handler method to your controller:
Directory Structure
Your module structure should look like this:
Understanding Picture Settings
Setting | Description | Default |
---|---|---|
destination |
Directory where pictures will be uploaded | Required |
upload_to_module |
If true, pictures are uploaded to the module's assets directory | false |
make_rand_name |
If true, generates a random filename for uploaded pictures | false |
target_column_name |
The database column that stores the filename | Required |
- Always validate file types to prevent unauthorized file uploads
- Set appropriate file size limits to prevent server overload
- Organize images in subdirectories by record ID
- Store only the filename in the database, not the full path
In the next section, we'll take a closer look at how file validation, including image validation, is handled with Trongate.