如何獲取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) –