To get root directory path in magento 2 use following code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
echo $rootdirPath = $directory->getRoot();
using following code you can get the other directories path also like:
echo $mediadirPath = $directory->getPath('media');
echo $vardirPath = $directory->getPath('var');
echo $pubdirPath = $directory->getPath('pub');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
echo $rootdirPath = $directory->getRoot();
using following code you can get the other directories path also like:
echo $mediadirPath = $directory->getPath('media');
echo $vardirPath = $directory->getPath('var');
echo $pubdirPath = $directory->getPath('pub');
Comments
Post a Comment