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
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communitythis will help
$files = $this->getRequest()->getFiles();
Here is Magento2 :: Accessing $_FILES using Magento Framework
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