21 class File extends \Magento\Framework\App\Config\Value
67 \
Magento\MediaStorage\Model\
File\UploaderFactory $uploaderFactory,
71 \
Magento\Framework\
Data\Collection\AbstractDb $resourceCollection =
null,
74 $this->_uploaderFactory = $uploaderFactory;
89 $value = $this->getValue();
95 $uploader = $this->_uploaderFactory->create([
'fileId' => $file]);
97 $uploader->setAllowRenameFiles(
true);
98 $uploader->addValidateCallback(
'size', $this,
'validateMaxSize');
99 $result = $uploader->save($uploadDir);
100 }
catch (\Exception $e) {
101 throw new \Magento\Framework\Exception\LocalizedException(
__(
'%1', $e->getMessage()));
109 $this->setValue($filename);
115 $this->setValue(
$value[
'value']);
133 $value = $this->getValue();
134 $tmpName = $this->_requestData->getTmpName($this->getPath());
136 $file[
'tmp_name'] = $tmpName;
137 $file[
'name'] = $this->_requestData->getName($this->getPath());
139 $file[
'tmp_name'] =
$value[
'tmp_name'];
156 if ($this->_maxFileSize > 0 && $directory->stat(
157 $directory->getRelativePath($filePath)
158 )[
'size'] > $this->_maxFileSize * 1024
160 throw new \Magento\Framework\Exception\LocalizedException(
161 __(
'The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxFileSize)
173 $fieldConfig = $this->getFieldConfig();
174 $dirParams = array_key_exists(
'upload_dir', $fieldConfig) ? $fieldConfig[
'upload_dir'] : [];
175 return is_array($dirParams) && array_key_exists(
'scope_info', $dirParams) && $dirParams[
'scope_info'];
186 $fieldConfig = $this->getFieldConfig();
188 if (!array_key_exists(
'upload_dir', $fieldConfig)) {
189 throw new \Magento\Framework\Exception\LocalizedException(
190 __(
'The base directory to upload file is not specified.')
194 if (is_array($fieldConfig[
'upload_dir'])) {
195 $uploadDir = $fieldConfig[
'upload_dir'][
'value'];
196 if (array_key_exists(
'scope_info', $fieldConfig[
'upload_dir'])
197 && $fieldConfig[
'upload_dir'][
'scope_info']
202 if (array_key_exists(
'config', $fieldConfig[
'upload_dir'])) {
206 $uploadDir = (string)$fieldConfig[
'upload_dir'];
221 return $this->_mediaDirectory->getAbsolutePath($uploadDir);
234 $scopeInfo = $this->getScope();
236 $scopeInfo .=
'/' . $this->getScopeId();
238 return $scopeInfo .
'/' .
$path;
251 $path .=
'/' . $this->getScope();
253 $path .=
'/' . $this->getScopeId();
elseif(isset( $params[ 'redirect_parent']))
validateMaxSize($filePath)
getUploadDirPath($uploadDir)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData, Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])