Getting Image from directory and show in frontend phtml MAGENTO2


  • From Admin When image uploaded it saves the only path of the image.
  • After getting collection get the path.
  •  After that



<div class="magzainListing">

  <ul>

  <?php

  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

   $body = $objectManager->get('Custom\module\Model\ResourceModel\Magazineinfo\Collection')->setOrder('id','ASC');;

  ?>

  <?php foreach ($body as $content) {

  $con=$content->getBlogContent(); 

  $image=$content->getBlogImage();   ///Image Path

  $title=$content->getBlogTitle();


  $storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
  $magimage =$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); 

  $imageUrl = $magimage.'/upload/images/'.$image;    //////// Folder==>>  upload/image  /////////

  ?>              

  <li>


  <img src=" <?php echo $imageUrl ?>">

  <!--   <img src="<?php// echo $block->getViewFileUrl('images/magazin_page_image01.jpg'); ?>"> -->

  <div class="innerbox">

  <span> <?php echo $title ?> </span>  

  <?php echo $con ;?>

           

  </div>        

  </li>

 <?php } 

   ?>

   <div class="clr"></div>

  </ul>

  </div>
  

Comments

Popular posts from this blog

Get Swatch Text Product id of Configurable Product in Detail Page through Jquery Magento2

Get Customer Address with customer ID programmatically Magento2

programmaticlly Create Order in Magento2 with custom options in order