How to get the root directory path in Magento 2?

You can use \Magento\Framework\Filesystem\DirectoryList class to get a directory path. You can get directory path of root, media, pub, var etc... Here is an example of how you can get root directory path. By ObjectManager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList'); echo $rootPath = $directory->getRoot(); By dependency Injection: protected $_dir; public function __construct( ... \Magento\Framework\Filesystem\DirectoryList…

Continue Reading How to get the root directory path in Magento 2?