For ECG you should avoid using "superglobals", but is there any Magento, Zend or Varien method to replace $_FILES
? Couldn't find anything in Mage_Core_Controller_Request_Http
or Zend_Controller_Request_Http
or Zend
docuomentation.
1 Answer
One way you can used Object Manager and Media Storage Uploader of magento to get $_FILES data.I know using object manager is not a good idea.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$fileSystem = $objectManager>create('\Magento\Framework\Filesystem');
$mediaPath=$fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath('/catalog/product');
$uploader = $objectManager->create('Magento\MediaStorage\Model\File\Uploader',['fileId' => 'file']);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
$imageAdapter = $objectManager->get('Magento\Framework\Image\AdapterFactory')->create();
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($mediaPath);
-
1quesrtion is abount magento1 not magento2,Please check question.– Amit Bera ♦Commented Jul 26, 2017 at 5:55