XF 2.2 uploading a file through a form


New member
Hi folks,

After watching Kier's wonderful development series for Xenforo 2 I began to make an add-on for my local community. Making the static pages was easy and those work beautifully. I'm at a part now where I am trying to make a form so admins can upload files to our game servers through Xenforo.
I've gotten the form mocked out:
                <xf:form action="" method="post" enctype="multipart/form-data">
                    <xf:upload name="upload" accept=".bsp,.bz2" type="file" name="mapfile[]" id="mapfile" multiple="multiple" style="padding: 100px 0px 100px 0px; text-align: center;"/>
                <xf:submitrow submit="{{ phrase('Upload') }}" fa="fa-upload" />

The part I am stuck at is trying to figure out how to/where to put the php script/function that the submit button would be calling after an admin uploads the files. Would I put something in "action" like you normally do in an html form? Is there something I call in the add-on controller? Any tips/direction pointing would be greatly appreciated :)
Last edited:


Active member
For starters, you would need to specify an action in your form tag. Let's say you put something like:

<xf:form action="{{ link("foo/bar") }}" method="post" enctype="multipart/form-data">

You'll then to specify a route (since it's admin specific, you should do it as a admin route rather than a public one) for that form action. So when the form is submitted, it will fetch the controller class and the method that you specify in the admin route.

Your then write the file handling code inside this controller class and its method.

This thread doesn't discuss it in detail but perhaps it would help you out with some things.