3

We are using $_FILES to check files post data in core php. Which class can use in Magento 2 to check files post data?

Thanks

5

this will help

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

Here is Magento2 :: Accessing $_FILES using Magento Framework

4
use Magento\MediaStorage\Model\File\UploaderFactory;

protected $uploaderFactory;


public function __construct(
    ...
    UploaderFactory $uploaderFactory    
    ....
) {
    ....
    $this->uploaderFactory = $uploaderFactory;  
    ....
}

    $uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
    $uploader->setFilesDispersion(false);
    $uploader->setFilenamesCaseSensitivity(false);
    $uploader->setAllowRenameFiles(true);
    $path='YOUR DIRECTORY PATH';
    $result = $uploader->save($path);

Where $fileId is your name of input file

2
  • Name of input field is groups[vbanktransfer][nineform] in that case what will be the $fileId ?? <input id="vbanktransfer-nineform" name="groups[vbanktransfer][nineform]" data-ui-id="widget-form-renderer-fieldset-element-0-file-groups-vbanktransfer-nineform" value="" type="file"> – Rahul Singh Jul 13 '20 at 16:17
  • It will create the issue (File size is empty) – mjdevloper Jul 29 '20 at 10:10

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.