'Magento 2 Directory '' is not under storage root path

App: Magento 2.3.7-p2

When executing \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Upload::execute

$this->getStorage()->getSession()->getCurrentPath()= '' although in the previous call

\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Contents::execute

the current Path was successfully saved via $this->_initAction()->_saveSessionCurrentPath().

I do not understand why $this->getStorage()->getSession()->getCurrentPath() = ''.



Solution 1:[1]

Run Below Command and check it

php bin/magento config:set system/security/max_session_size_admin 0

php bin/magento c:f

If your Folder is not showing than create below code:

For security purposes, Magento provides Media Gallery access to contents in specific folders. The configuration path system/media_storage_configuration/media_storage/allowed_resource/media_gallery_image_folders in config.xml is used to define “Media Gallery Allowed” folders

By default, Magento allows Media Gallery access to the following two directories under /pub/media:

  • catalog/category

  • wysiwyg

app/code/VendoreName/ModuleName/etc

config.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <system>
            <media_storage_configuration>
                <allowed_resources>
                    <catalog_images_folder>catalog</catalog_images_folder> <!-- Show Catalog Folder -->
                    <media_gallery_image_folders>
                        <category_image_folder>catalog/category</category_image_folder> <!--  Show Sub Catalog Folder -->
                        <my_image_folder>custom_folder_name</my_image_folder>
                        <my_catalog_image_folder>catalog/custom_folder_name</my_catalog_image_folder>
                    </media_gallery_image_folders>
                </allowed_resources>
            </media_storage_configuration>
        </system>
    </default>
</config>

I Hope This Helps You.

Solution 2:[2]

Try your luck after increasing the maximum session size limit for admin. Store configuration is at path

Stores > Settings > Configuration > Advanced > System > Security > Max Session Size in Admin

I debugged the same problem and ended up finding out that there are some important values to get in to admin session, which unfortunately isn't happening due to this size limit.

Solution 3:[3]

For temporary fix you can just return true, it will solve all your issues.

public function validatePath($path, $directoryConfig = DirectoryList::MEDIA)
    {
        $directory = $this->filesystem->getDirectoryWrite($directoryConfig);
        $realPath = realpath($directory->getDriver()->getRealPathSafety($path));
        $root = rtrim($directory->getAbsolutePath(), DIRECTORY_SEPARATOR);

        return true;
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Msquare
Solution 2 Wasim Bajwa
Solution 3 ravichandra