97 \
Magento\Framework\Image\AdapterFactory $imageFactory,
104 $this->_imageFactory = $imageFactory;
116 public function uploadFile($targetPath)
119 $uploader = $this->_objectManager->create(
120 \
Magento\MediaStorage\Model\File\Uploader::class,
123 $uploader->setAllowedExtensions($this->_helper->getAllowedExtensionsByType());
124 $uploader->setAllowRenameFiles(
true);
125 $uploader->setFilesDispersion(
false);
126 $result = $uploader->save($targetPath);
130 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We can\'t upload the file right now.'));
133 $this->
_createThumbnail($targetPath .
'/' . $uploader->getUploadedFileName());
146 if (self::TYPE_IMAGE != $this->_helper->getStorageType() || !$this->mediaWriteDirectory->isFile(
148 ) || !$this->mediaWriteDirectory->isReadable(
154 $thumbnailDir = $this->_helper->getThumbnailDirectory(
$source);
155 $thumbnailPath = $thumbnailDir .
'/' . pathinfo(
$source, PATHINFO_BASENAME);
157 $this->mediaWriteDirectory->isExist($thumbnailDir);
158 $image = $this->_imageFactory->create();
159 $image->open($this->mediaWriteDirectory->getAbsolutePath(
$source));
160 $image->keepAspectRatio(
true);
161 $image->resize(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT);
162 $image->save($this->mediaWriteDirectory->getAbsolutePath($thumbnailPath));
163 }
catch (\
Magento\Framework\Exception\FileSystemException $e) {
164 $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
168 if ($this->mediaWriteDirectory->isFile($thumbnailPath)) {
169 return $thumbnailPath;
184 if (!preg_match(self::DIRECTORY_NAME_REGEXP,
$name)) {
185 throw new \Magento\Framework\Exception\LocalizedException(
186 __(
'Use only standard alphanumeric, dashes and underscores.')
189 if (!$this->mediaWriteDirectory->isWritable(
$path)) {
190 $path = $this->_helper->getStorageRoot();
195 if ($this->mediaWriteDirectory->isExist($newPath)) {
196 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We found a directory with the same name.'));
199 $this->mediaWriteDirectory->create($newPath);
203 'short_name' => $this->_helper->getShortFilename(
$name),
204 'path' => str_replace($this->_helper->getStorageRoot(),
'', $newPath),
205 'id' => $this->_helper->convertPathToId($newPath)
219 $file = $this->urlDecoder->decode($file);
220 $path = $this->mediaWriteDirectory->getRelativePath($this->_helper->getCurrentPath());
222 $filePath = $this->mediaWriteDirectory->getRelativePath(
$path .
'/' . $file);
223 $thumbnailPath = $this->_helper->getThumbnailDirectory($filePath) .
'/' . $file;
225 if (0 === strpos($filePath,
$path) && 0 === strpos($filePath, $this->_helper->getStorageRoot())) {
226 $this->mediaWriteDirectory->delete($filePath);
227 $this->mediaWriteDirectory->delete($thumbnailPath);
241 if (!$this->mediaWriteDirectory->isExist($currentPath)) {
242 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We cannot find a directory with this name.'));
244 $paths = $this->mediaWriteDirectory->search(
'.*', $currentPath);
247 if ($this->mediaWriteDirectory->isDirectory(
$path)) {
248 $directories[] =
$path;
261 $paths = $this->mediaWriteDirectory->search(
'.*', $this->_helper->getCurrentPath());
263 $requestParams = $this->_helper->getRequestParams();
264 $storageType = $this->_helper->getStorageType();
266 if (!$this->mediaWriteDirectory->isFile(
$path)) {
271 if (self::TYPE_IMAGE == $storageType) {
273 $file[
'thumbnailParams'] = $requestParams;
276 if (is_array($size)) {
277 $file[
'width'] = $size[0];
278 $file[
'height'] = $size[1];
295 foreach ($directories as
$path) {
297 'text' => $this->_helper->getShortFilename(pathinfo(
$path, PATHINFO_BASENAME), 20),
298 'id' => $this->_helper->convertPathToId(
$path),
314 $rootCmp = rtrim($this->_helper->getStorageRoot(),
'/');
315 $pathCmp = rtrim(
$path,
'/');
317 if ($rootCmp == $pathCmp) {
318 throw new \Magento\Framework\Exception\LocalizedException(
319 __(
'We can\'t delete root directory %1 right now.',
$path)
323 return $this->mediaWriteDirectory->delete(
$path);
createFolder($name, $path)
const DIRECTORY_NAME_REGEXP
getDirsCollection($currentPath)
__construct(\Magento\Framework\Filesystem $filesystem, \Magento\Theme\Helper\Storage $helper, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Image\AdapterFactory $imageFactory, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\Framework\Url\DecoderInterface $urlDecoder)
_createThumbnail($source)
const THUMBNAIL_DIRECTORY
foreach($appDirs as $dir) $files
if(!isset($_GET['name'])) $name