如何获取Magento2中媒体文件的绝对路径? 我写了一个函数来获取绝对路径,但它不工作。Magento2中的绝对路径
public function getAbsolutePath()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $objectManager->get('Magento\Framework\Filesystem');
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
$mediaDirectory = $filesystem->getDirectoryWrite(Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$mediaPath = $mediaDirectory->getAbsolutePath();
return $mediaPath;
}
你能解释一下你的答案吗? [来自评论](http://stackoverflow.com/review/low-quality-posts/11855039) –