I have a file-input field in my pthml and would like to use it to upload picture files.

                <div class="field file">
                    <label class="label" for="email"><span><?= $escaper->escapeHtmlAttr(__('Attach a picture')) ?></span></label>
                    <div class="control">
                        <input name="pictureUpload"

My Post-Controller works with all other inputs but not with the file. I tried getting it via $this->getRequest()->getFiles(); and checked $_FILES but it remains empty. Is there another component involved that I'm missing?

My Controller extends \Magento\Framework\App\Action\Action and implements Magento\Framework\App\Action\HttpPostActionInterface.

1 Answer 1


Please check with below example your form all attributes is same like this.

<form id="contact-form" class="form contact" action="Your action" method="post" enctype="multipart/form-data">

This Form attribute enctype="multipart/form-data" is needed when you use file input in your phtml file.

In controller you can try below code for get input data.

$files = $this->getRequest()->getFiles();

Hope it will work for you!

  • That is exactly what was missing. Thank you kindly!
    – Hurrpadurr
    Sep 9, 2021 at 9:17
  • Most welcome buddy 🙂 Sep 10, 2021 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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