Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Upload Class Reference
Inheritance diagram for Upload:
File HttpPostActionInterface Action ActionInterface AbstractAction Action AbstractAction ActionInterface

Public Member Functions

 __construct (\Magento\Backend\App\Action\Context $context, \Magento\Downloadable\Model\Link $link, \Magento\Downloadable\Model\Sample $sample, \Magento\Downloadable\Helper\File $fileHelper, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, \Magento\MediaStorage\Helper\File\Storage\Database $storageDatabase)
 
 execute ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Action\Context $context)
 
 dispatch (\Magento\Framework\App\RequestInterface $request)
 
 _processUrlKeys ()
 
 getUrl ($route='', $params=[])
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 

Protected Attributes

 $_link
 
 $_sample
 
 $_fileHelper
 
- Protected Attributes inherited from AbstractAction
 $_publicActions = []
 
 $_sessionNamespace = self::SESSION_NAMESPACE
 
 $_helper
 
 $_session
 
 $_authorization
 
 $_auth
 
 $_backendUrl
 
 $_localeResolver
 
 $_canUseBaseUrl
 
 $_formKeyValidator
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Additional Inherited Members

- Data Fields inherited from File
const ADMIN_RESOURCE = 'Magento_Catalog::products'
 
- Data Fields inherited from AbstractAction
const FLAG_IS_URLS_CHECKED = 'check_url_settings'
 
const SESSION_NAMESPACE = 'adminhtml'
 
const ADMIN_RESOURCE = 'Magento_Backend::admin'
 
- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 
- Protected Member Functions inherited from AbstractAction
 _isAllowed ()
 
 _getSession ()
 
 getMessageManager ()
 
 _addBreadcrumb ($label, $title, $link=null)
 
 _addContent (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addLeft (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addJs (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _isUrlChecked ()
 
 _processLocaleSettings ()
 
 _redirect ($path, $arguments=[])
 
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _validateSecretKey ()
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Detailed Description

Definition at line 16 of file Upload.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\App\Action\Context  $context,
\Magento\Downloadable\Model\Link  $link,
\Magento\Downloadable\Model\Sample  $sample,
\Magento\Downloadable\Helper\File  $fileHelper,
\Magento\MediaStorage\Model\File\UploaderFactory  $uploaderFactory,
\Magento\MediaStorage\Helper\File\Storage\Database  $storageDatabase 
)

Copyright © Magento, Inc. All rights reserved. See COPYING.txt for license details.

Parameters
\Magento\Backend\App\Action\Context$context
\Magento\Downloadable\Model\Link$link
\Magento\Downloadable\Model\Sample$sample
\Magento\Downloadable\Helper\File$fileHelper
\Magento\MediaStorage\Model\File\UploaderFactory$uploaderFactory
\Magento\MediaStorage\Helper\File\Storage\Database$storageDatabase

Definition at line 56 of file Upload.php.

63  {
64  parent::__construct($context);
65  $this->_link = $link;
66  $this->_sample = $sample;
67  $this->_fileHelper = $fileHelper;
68  $this->uploaderFactory = $uploaderFactory;
69  $this->storageDatabase = $storageDatabase;
70  }

Member Function Documentation

◆ execute()

execute ( )

Upload file controller action

Returns
\Magento\Framework\Controller\ResultInterface

Implements ActionInterface.

Definition at line 77 of file Upload.php.

78  {
79  $type = $this->getRequest()->getParam('type');
80  $tmpPath = '';
81  if ($type == 'samples') {
82  $tmpPath = $this->_sample->getBaseTmpPath();
83  } elseif ($type == 'links') {
84  $tmpPath = $this->_link->getBaseTmpPath();
85  } elseif ($type == 'link_samples') {
86  $tmpPath = $this->_link->getBaseSampleTmpPath();
87  }
88 
89  try {
90  $uploader = $this->uploaderFactory->create(['fileId' => $type]);
91 
92  $result = $this->_fileHelper->uploadFromTmp($tmpPath, $uploader);
93 
94  if (!$result) {
95  throw new \Exception('File can not be moved from temporary folder to the destination folder.');
96  }
97 
98  unset($result['tmp_name'], $result['path']);
99 
100  if (isset($result['file'])) {
101  $relativePath = rtrim($tmpPath, '/') . '/' . ltrim($result['file'], '/');
102  $this->storageDatabase->saveFile($relativePath);
103  }
104  } catch (\Exception $e) {
105  $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
106  }
107 
108  return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
109  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$relativePath
Definition: get.php:35

Field Documentation

◆ $_fileHelper

$_fileHelper
protected

Definition at line 33 of file Upload.php.

◆ $_link

$_link
protected

Definition at line 21 of file Upload.php.

◆ $_sample

$_sample
protected

Definition at line 26 of file Upload.php.


The documentation for this class was generated from the following file: