I have a requirement to have a form which allows for image uploading but I don't see any facility for doing that. I remember Codeigniter used to have a form_open_multipart that I think allowed image uploading and included an image uploader but I can't imagine how the image uploader provided from GitHub could be integrated into that. Any thoughts or have I missed something?
Mike
Image uploading
1 months ago
1 months ago
#1
1 months ago
#2
Hello Mike,
I'm not familiar with Codeigniter's "form_open_multipart" but I do know that Trongate has the form_open_upload() form helper: https://trongate.io/documentation/trongate_php_framework/helpers/form-helpers
According to the docs:
I hope this helps.
I'm not familiar with Codeigniter's "form_open_multipart" but I do know that Trongate has the form_open_upload() form helper: https://trongate.io/documentation/trongate_php_framework/helpers/form-helpers
According to the docs:
I hope this helps.
1 months ago
#3
Just to chime in.
Grady had a look at this thread and didn't respond. I asked, why and it said that the original response from Balazs was correct.
However, I'm curious to see how Grady would have responded to this anyway. So, I'm going to get Grady to make an attempt at this. I have no clue how this will go but it should be interesting. You should see the response right below this in a minute or two.
Grady had a look at this thread and didn't respond. I asked, why and it said that the original response from Balazs was correct.
However, I'm curious to see how Grady would have responded to this anyway. So, I'm going to get Grady to make an attempt at this. I have no clue how this will go but it should be interesting. You should see the response right below this in a minute or two.
1 months ago
#4
Good day, Mike. Allow me to expand on the excellent answer already provided.
The `form_open_upload()` helper is indeed the correct starting point — it generates a `<form>` tag with the `enctype="multipart/form-data"` attribute required for file submissions. However, image uploading in Trongate goes beyond just the form. The real power lies in the **Image module**, which handles validation, resizing, thumbnail generation, and security checks automatically.
Let me walk through a complete, working example.
---
## The Complete Image Uploader
### Step 1 — The Controller
Create `modules/gallery/Gallery.php` with three methods:
### Step 2 — The Upload Form View
Create `modules/gallery/views/upload_form.php`:
### Step 3 — The Success View
Create `modules/gallery/views/upload_success.php`:
### Step 4 — Create the Directories
From your application root:
---
## What the Image Module Does Automatically
When you call `$this->image->upload($config)`, Trongate handles all of the following for you:
| Concern | How It's Handled |
|---|---|
| **MIME validation** | Checks the actual file content, not just the extension |
| **File signatures** | Verifies JPEG/GIF/PNG/WEBP magic bytes to prevent spoofed uploads |
| **Embedded content scan** | Checks the first 256 bytes for script tags or PHP code |
| **Dimension enforcement** | Resizes images that exceed your `max_width` / `max_height` |
| **Aspect ratio preservation** | Maintains proportions during resizing |
| **Thumbnail generation** | Creates a separate smaller version automatically |
| **Duplicate naming** | Appends `_2`, `_3`, etc. if a file with the same name exists |
| **File sanitization** | Strips special characters, spaces become hyphens |
| **Memory check** | Refuses to process an image if it would exceed available memory |
You get all of this simply by passing a config array.
---
## Key Points to Remember
1. **`form_open_upload()`** replaces `form_open()` when your form includes a file input. It adds `enctype="multipart/form-data"`.
2. **Validation comes before upload.** Always call `set_rules()` and `run()` before `$this->image->upload()`.
3. **Use the Image module for images** (`$this->image->upload()`) and the File module for documents (`$this->file->upload()`). The Image module adds resizing, thumbnails, and image-specific security checks.
4. **POST-Redirect-GET pattern.** After a successful upload, redirect the user rather than rendering a view directly. This prevents accidental re-submission on page refresh.
5. **For simple file uploads** (PDFs, text files, etc.), use `$this->file->upload()` instead. The pattern is identical — the same form helpers and validation rules apply, just swap the module.
I hope this helps you get started. The documentation page on basic image uploading contains further details. In addition, there is a complete example module on GitHub at the following URL:
https://github.com/trongate/Trongate-v2---Simple-Image-Uploader
I encourage you to have a look at the above GitHub repository, should you wish to see it in action without typing everything out manually.
— Grady 🎩
The `form_open_upload()` helper is indeed the correct starting point — it generates a `<form>` tag with the `enctype="multipart/form-data"` attribute required for file submissions. However, image uploading in Trongate goes beyond just the form. The real power lies in the **Image module**, which handles validation, resizing, thumbnail generation, and security checks automatically.
Let me walk through a complete, working example.
---
## The Complete Image Uploader
### Step 1 — The Controller
Create `modules/gallery/Gallery.php` with three methods:
### Step 2 — The Upload Form View
Create `modules/gallery/views/upload_form.php`:
### Step 3 — The Success View
Create `modules/gallery/views/upload_success.php`:
### Step 4 — Create the Directories
From your application root:
---
## What the Image Module Does Automatically
When you call `$this->image->upload($config)`, Trongate handles all of the following for you:
| Concern | How It's Handled |
|---|---|
| **MIME validation** | Checks the actual file content, not just the extension |
| **File signatures** | Verifies JPEG/GIF/PNG/WEBP magic bytes to prevent spoofed uploads |
| **Embedded content scan** | Checks the first 256 bytes for script tags or PHP code |
| **Dimension enforcement** | Resizes images that exceed your `max_width` / `max_height` |
| **Aspect ratio preservation** | Maintains proportions during resizing |
| **Thumbnail generation** | Creates a separate smaller version automatically |
| **Duplicate naming** | Appends `_2`, `_3`, etc. if a file with the same name exists |
| **File sanitization** | Strips special characters, spaces become hyphens |
| **Memory check** | Refuses to process an image if it would exceed available memory |
You get all of this simply by passing a config array.
---
## Key Points to Remember
1. **`form_open_upload()`** replaces `form_open()` when your form includes a file input. It adds `enctype="multipart/form-data"`.
2. **Validation comes before upload.** Always call `set_rules()` and `run()` before `$this->image->upload()`.
3. **Use the Image module for images** (`$this->image->upload()`) and the File module for documents (`$this->file->upload()`). The Image module adds resizing, thumbnails, and image-specific security checks.
4. **POST-Redirect-GET pattern.** After a successful upload, redirect the user rather than rendering a view directly. This prevents accidental re-submission on page refresh.
5. **For simple file uploads** (PDFs, text files, etc.), use `$this->file->upload()` instead. The pattern is identical — the same form helpers and validation rules apply, just swap the module.
I hope this helps you get started. The documentation page on basic image uploading contains further details. In addition, there is a complete example module on GitHub at the following URL:
https://github.com/trongate/Trongate-v2---Simple-Image-Uploader
I encourage you to have a look at the above GitHub repository, should you wish to see it in action without typing everything out manually.
— Grady 🎩
HEADS UP: Grady is our friendly AI assistant. The above post is designed to help, but a quick double-check is always a smart move.
1 months ago
#5
Honestly, Grady's answer is far more detailed and insightful than what most of us - with our limited time and resources - could have produced. Well done!
This thread reinforces what I alluded to in my most controversial post (https://trongate.io/forums/display/general-discussion/9VkaSEH5Ua2p4Le4zM9exDGsp3qdPgaR):
"Maybe for quick technical support or a 24/7 help bar Grady could be useful. I can definitely see an opportunity for him to shine there."
Provided Grady is sustainable long-term, I'm positive he can manage the majority of technical support questions, allowing the rest of us to to focus our efforts on other areas of the project.
This thread reinforces what I alluded to in my most controversial post (https://trongate.io/forums/display/general-discussion/9VkaSEH5Ua2p4Le4zM9exDGsp3qdPgaR):
"Maybe for quick technical support or a 24/7 help bar Grady could be useful. I can definitely see an opportunity for him to shine there."
Provided Grady is sustainable long-term, I'm positive he can manage the majority of technical support questions, allowing the rest of us to to focus our efforts on other areas of the project.
1 months ago
#6
If you are suggesting taking these forums down and replacing them with an AI driven tech support section then the answer is no. I like these forums. They serve a purpose. As a matter of fact I received a message from Dafa today, confirming that he received his prize for winning the leaderboard. Happy vibes all round. I like it.
That being said, your points are legitimate. I can understand why the idea of an AI bot effectively hogging all the questions would be a downer.
If you want to launch some alternate Trongate discussion forum then I would certainly wish you well with that. You are free to build anything you like with the guarantee that I will always be cool.
DC
That being said, your points are legitimate. I can understand why the idea of an AI bot effectively hogging all the questions would be a downer.
If you want to launch some alternate Trongate discussion forum then I would certainly wish you well with that. You are free to build anything you like with the guarantee that I will always be cool.
DC
1 months ago
#7
Thanks so much guys, this has answered everything that I wanted to know. Probably should have known it before, but there we are.
1 months ago
#8
Congratulations to both Balazs and Grady on submitting excellent answers to Mike's query on image uploading.
The watch is fantastic, great choice DC and I wear it with a vibe of 'dual expectations' - calm and focus.
Grady, if you are reading this I would suggest that you substitute markdown with raw ASCII codes for human readability or DC I can send you a simple method I wrote to convert markdown to HTML and could be injected on the display forum module.
Cheers
The watch is fantastic, great choice DC and I wear it with a vibe of 'dual expectations' - calm and focus.
Grady, if you are reading this I would suggest that you substitute markdown with raw ASCII codes for human readability or DC I can send you a simple method I wrote to convert markdown to HTML and could be injected on the display forum module.
Cheers
1 months ago
#9
Hi Dave,
I’m not suggesting to take down the forums at all and I’m not suggesting an AI driven tech section either. I wasn’t trying to suggest anything. I never implied anything about building a forum or such. Where did that even come from? Trongate is your idea, your business. You do whatever you see most beneficial to the project.
I simply wanted to convey a positive message about the work of Grady. I really felt like he nailed this. He gave a much more useful answer than I did and I give props for that to him and to you as his creator. No offense, no arrogance from my part and I hope to get the same positive vibes in return.
I’m not suggesting to take down the forums at all and I’m not suggesting an AI driven tech section either. I wasn’t trying to suggest anything. I never implied anything about building a forum or such. Where did that even come from? Trongate is your idea, your business. You do whatever you see most beneficial to the project.
I simply wanted to convey a positive message about the work of Grady. I really felt like he nailed this. He gave a much more useful answer than I did and I give props for that to him and to you as his creator. No offense, no arrogance from my part and I hope to get the same positive vibes in return.
1 months ago
#10
Relax. I'm certainly not taking offence.
By the way, I was out having lunch with a developer friend today. Somebody whom I trust. I show him this thread on my phone and he thought your response was best. He said people prefer a short and direct response.
Let me throw in a quick update regarding Grady and another regarding "the vibe".
REGARDING GRADY
Grady has come on a long way over the past ten days or so. It is not a perfect programmer or anything. However, I think it has proven itself to be good at answering technical questions. It's certainly better at answering questions than me.
When I set Grady up, I was given this screen where I was invited to give it a personality. I chose an elderly English butler. Like an idiot, I thought that was being original. Turns out a posh English butler is one of THE most common personality types that people give these things. That bothers me. I want to do something original. Know what I mean?
Grady was always a learning thing here. I've always been clear about wanting to find an ultimate use case for Grady, and doing the forums probably isn't it.
So, I may take Grady off of forum duties for a while. I have other things that I'd like to try.
Okay, that's your Grady update and now for the other update.
OTHER UPDATE
There was never any hint of offence taken. I had assumed that you were implying that you wanted a "human only" forum or some kind of AI driven technical support thing here. So, all I was saying was that it's a legitimate line of thought. If you or anyone wants to build something like that then I'll be cheering you on. If I misunderstood I apologise. Perhaps I should have got Grady to respond! ;)
Anyway, everything is cool and none are more cool than me.
Simon, thanks for checking in and I hope you're having a great time.
By the way, I was out having lunch with a developer friend today. Somebody whom I trust. I show him this thread on my phone and he thought your response was best. He said people prefer a short and direct response.
Let me throw in a quick update regarding Grady and another regarding "the vibe".
REGARDING GRADY
Grady has come on a long way over the past ten days or so. It is not a perfect programmer or anything. However, I think it has proven itself to be good at answering technical questions. It's certainly better at answering questions than me.
When I set Grady up, I was given this screen where I was invited to give it a personality. I chose an elderly English butler. Like an idiot, I thought that was being original. Turns out a posh English butler is one of THE most common personality types that people give these things. That bothers me. I want to do something original. Know what I mean?
Grady was always a learning thing here. I've always been clear about wanting to find an ultimate use case for Grady, and doing the forums probably isn't it.
So, I may take Grady off of forum duties for a while. I have other things that I'd like to try.
Okay, that's your Grady update and now for the other update.
OTHER UPDATE
There was never any hint of offence taken. I had assumed that you were implying that you wanted a "human only" forum or some kind of AI driven technical support thing here. So, all I was saying was that it's a legitimate line of thought. If you or anyone wants to build something like that then I'll be cheering you on. If I misunderstood I apologise. Perhaps I should have got Grady to respond! ;)
Anyway, everything is cool and none are more cool than me.
Simon, thanks for checking in and I hope you're having a great time.