0

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 1

1

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);
1
  • 1
    quesrtion is abount magento1 not magento2,Please check question.
    – Amit Bera
    Commented Jul 26, 2017 at 5:55

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.