title: Absolute path in Magento2
body: <p>How can I get the absolute path of a media file in Magento2?
  I write a function to get the absolute path, but it is not working.</p>
  
  <pre><code>public function getAbsolutePath()
      {
          $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
          /** @var \Magento\Framework\Filesystem $filesystem */
          $filesystem = $objectManager-&gt;get('Magento\Framework\Filesystem');
          /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
          $mediaDirectory = $filesystem-&gt;getDirectoryWrite(Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
          $mediaPath = $mediaDirectory-&gt;getAbsolutePath();
          return $mediaPath;
      }
  </code></pre>