<p>That field accepts any valid Twig code, so something like this should work:</p>

<pre><code>challenges/{{ craft.request.getPost('challenge_id') }}/
</code></pre>

<p>Fair warning, though... I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.</p>

CC BY-SA 3.0
2017-04-17T15:32:26.947Z
This seems pretty dangerous, unless Craft automatically prevents users from writing to directories outside the install (i.e. a user in the front-end passing in `../../../usr/bin/` or something malicious)…
August Miller
CC BY-SA 3.0
2017-04-17T20:24:23.110Z
Craft does some bounds checking for situations like this, but I added the warning in my initial comment to the answer, too.
Brad Bell
CC BY-SA 3.0
2017-04-15T17:17:17.157Z
2017-04-17T18:48:40.417Z
2017-04-17T18:48:40.417Z
Brad Bell
<p>How can I use a request variable used in an upload form like this?</p>

<pre><code>&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
&lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
&lt;input type="hidden" name="sectionId" value="29"&gt;
&lt;input type="hidden" name="enabled" value="1"&gt;
&lt;input type="file" name="fields[useruploads]"&gt;
&lt;input type="text" name="challenge_id"&gt;
...
</code></pre>

<p>The idea is to use the field "challenge_id" as dynamic upload location.</p>

<p><a href="https://i.sstatic.net/2oQYf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2oQYf.png" alt="enter image description here"></a></p>

<p>Is there a way to get this?</p>

CC BY-SA 3.0
2017-04-13T18:37:51.820Z
Try something like `challenges/{{ craft.request.getPost('challenge_id') }}/`? I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.
Brad Bell
CC BY-SA 3.0
2017-04-15T14:30:24.487Z
@Brad Bell: it works - the hint hearby the field "... like {slug] or ..." is misleading, because I have done all my tries with one curly brace.
Marco
<upload><request><files>
Use REQUEST variable as dynamic upload location
# Use REQUEST variable as dynamic upload location

(Asked by: username_0 on 2017-04-13)

How can I use a request variable used in an upload form like this?






...

The idea is to use the field "challenge_id" as dynamic upload location.

Is there a way to get this?

**Tags:** upload, request, files
> **Comments:**
> **username_1**: Try something like `challenges/{{ craft.request.getPost('challenge_id') }}/`? I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.  
> **username_0**: @Brad Bell: it works - the hint hearby the field "... like {slug] or ..." is misleading, because I have done all my tries with one curly brace.  

---

## 1 answers

### Answer by username_1 on 2017-04-15. Score: 1 | Accepted answer

That field accepts any valid Twig code, so something like this should work:
challenges/{{ craft.request.getPost('challenge_id') }}/

Fair warning, though... I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.

> **Comments:**
> **username_2**: This seems pretty dangerous, unless Craft automatically prevents users from writing to directories outside the install (i.e. a user in the front-end passing in `../../../usr/bin/` or something malicious)…  
> **username_1**: Craft does some bounds checking for situations like this, but I added the warning in my initial comment to the answer, too.  

---

