Call Function in Block file,
Class Test{
protected $storeManager;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
../////
) {
$this->storeManager = $storeManager;
..////
}
public function getMediaimg(){
$folderName = 'cusotomimg';
$imgname = 'abc.jpg';
$path = $folderName . '/' . $imgname;
return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path;
}
}
Now call inside phtml file,
<?php echo $block->getMediaimg(); ?>
Directly using objectmanager, this is not recommended way but you can check its using directly in phtml file instead of using objectmanager you can using Block file
$om = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $om->get('Magento\Store\Model\StoreManagerInterface');
$folderName = 'cusotomimg';
$imgname = 'abc.jpg';
$path = $folderName . '/' . $imgname;
echo $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path;