Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-media-gallery-ui/Controller/Adminhtml/Image/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-media-gallery-ui/Controller/Adminhtml/Image/Upload.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\MediaGalleryUi\Controller\Adminhtml\Image;

use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\MediaGalleryUi\Model\UploadImage;
use Psr\Log\LoggerInterface;

/**
 * Controller responsible to upload the media gallery content
 */
class Upload extends Action implements HttpPostActionInterface
{
    private const HTTP_OK = 200;
    private const HTTP_BAD_REQUEST = 400;

    /**
     * @see _isAllowed()
     */
    public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::upload_assets';

    /**
     * @var UploadImage
     */
    private $uploadImage;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @param Context $context
     * @param UploadImage $upload
     * @param LoggerInterface $logger
     */
    public function __construct(
        Context $context,
        UploadImage $upload,
        LoggerInterface $logger
    ) {
        parent::__construct($context);
        $this->uploadImage = $upload;
        $this->logger = $logger;
    }

    /**
     * @inheritDoc
     */
    public function execute()
    {
        /** @var Json $resultJson */
        $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
        $targetFolder = $this->getRequest()->getParam('target_folder');
        $type = $this->getRequest()->getParam('type');

        if (!$targetFolder) {
            $responseContent = [
                'success' => false,
                'message' => __('The target_folder parameter is required.'),
            ];
            $resultJson->setHttpResponseCode(self::HTTP_BAD_REQUEST);
            $resultJson->setData($responseContent);
            return $resultJson;
        }

        try {
            $this->uploadImage->execute($targetFolder, $type);
            $responseCode = self::HTTP_OK;
            $responseContent = [
                'success' => true,
                'message' => __('The image was uploaded successfully.'),
            ];
        } catch (LocalizedException $exception) {
            $responseCode = self::HTTP_OK;
            $responseContent = [
                'success' => false,
                'message' => $exception->getMessage(),
            ];
        } catch (Exception $exception) {
            $this->logger->critical($exception);
            $responseCode = self::HTTP_OK;
            $responseContent = [
                'success' => false,
                'message' => __('Could not upload image.'),
            ];
        }

        $resultJson->setHttpResponseCode($responseCode);
        $resultJson->setData($responseContent);
        return $resultJson;
    }
}

Spamworldpro Mini