2

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

2

this will help

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

Here is Magento2 :: Accessing $_FILES using Magento Framework

3
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

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.