Action.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Controller\Adminhtml\Upload\Image;
  9. use Magento\Framework\Controller\ResultFactory;
  10. /**
  11. * Blog image upload controller
  12. */
  13. abstract class Action extends \Magento\Catalog\Controller\Adminhtml\Category\Image\Upload
  14. {
  15. /**
  16. * File key
  17. *
  18. * @var string
  19. */
  20. protected $_fileKey;
  21. public function execute()
  22. {
  23. try {
  24. $result = $this->imageUploader->saveFileToTmpDir($this->_fileKey);
  25. $result['cookie'] = [
  26. 'name' => $this->_getSession()->getName(),
  27. 'value' => $this->_getSession()->getSessionId(),
  28. 'lifetime' => $this->_getSession()->getCookieLifetime(),
  29. 'path' => $this->_getSession()->getCookiePath(),
  30. 'domain' => $this->_getSession()->getCookieDomain(),
  31. ];
  32. } catch (\Exception $e) {
  33. $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
  34. }
  35. return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
  36. }
  37. }