1

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

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

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

enter image description here

Is there a way to get this?

  • 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. – Brad Bell Apr 13 '17 at 18:37
  • @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 Apr 15 '17 at 14:30
1

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.

| improve this answer | |
  • 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 Apr 17 '17 at 15:32
  • 2
    Craft does some bounds checking for situations like this, but I added the warning in my initial comment to the answer, too. – Brad Bell Apr 17 '17 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.