Using Joomla's file uploader in own components

56 views
Skip to first unread message

René Kreijveld

unread,
Feb 24, 2021, 8:02:22 AM2/24/21
to Joomla! General Development
Hi all,

I have a component where website visitors fill in a form and the form also has file upload fields.
In my model I have a save method that saves the form data and handles the uploaded files.
For the file upload I have a simple field of this type in my form.xml:

<field name="report" type="file" accept="image/*,.pdf" required="true" />

This all works fine.

Now what I would like, is to use the ajax file uploader that's built into Joomla and that is used when installing extensions. Does anyone have example code how to use this ajax file uploader in own components?

Thanks,
René

Viper

unread,
Feb 24, 2021, 9:47:17 AM2/24/21
to Joomla! General Development

Or use install.json.php as controller name if you do not want to
1. Send header(),
2. use this crutch $app->getSession()->set('application.queue', $app->getMessageQueue());
3. use JResponseJson.

Just remember to set format=json in you request URL.

IMO it's best to use raw format as you can send anything in response. And do not use Joomla uploader as it very basic. See dropzonejs script as client-side.
Reply all
Reply to author
Forward
0 new messages