How to get the image directory

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3














I need to get image directory means full path.
I get the image path from the following code



$product = $this->productmodel->load($orderItem->getProductId());
$product->getThumbnail();


I got url



/w/b/wb02-green-0.jpg


I need



 /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg


How do i get that
i did following code



$path = $this->directorylist->getPath("media");


it returns



/var/www/html/magento/pub/media


but i need



/var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg









share|improve this question


























    3














    I need to get image directory means full path.
    I get the image path from the following code



    $product = $this->productmodel->load($orderItem->getProductId());
    $product->getThumbnail();


    I got url



    /w/b/wb02-green-0.jpg


    I need



     /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg


    How do i get that
    i did following code



    $path = $this->directorylist->getPath("media");


    it returns



    /var/www/html/magento/pub/media


    but i need



    /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg









    share|improve this question
























      3












      3








      3







      I need to get image directory means full path.
      I get the image path from the following code



      $product = $this->productmodel->load($orderItem->getProductId());
      $product->getThumbnail();


      I got url



      /w/b/wb02-green-0.jpg


      I need



       /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg


      How do i get that
      i did following code



      $path = $this->directorylist->getPath("media");


      it returns



      /var/www/html/magento/pub/media


      but i need



      /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg









      share|improve this question













      I need to get image directory means full path.
      I get the image path from the following code



      $product = $this->productmodel->load($orderItem->getProductId());
      $product->getThumbnail();


      I got url



      /w/b/wb02-green-0.jpg


      I need



       /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg


      How do i get that
      i did following code



      $path = $this->directorylist->getPath("media");


      it returns



      /var/www/html/magento/pub/media


      but i need



      /var/www/html/magento/pub/media/catalog/product/w/b/wb02-green-0.jpg






      image magento2.2.6 directory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 19 '18 at 14:13









      Sammu Sundar

      779




      779




















          2 Answers
          2






          active

          oldest

          votes


















          2














          First, inject below class in your constructor



           use MagentoCatalogModelProductMediaConfig;
          use MagentoFrameworkFilesystem;


          /**
          * @var Config
          */
          private $mediaConfig;

          /**
          * @var Filesystem
          */
          private $filesystem;


          /**
          * @param Config $mediaConfig
          * @param Filesystem $filesystem
          */
          public function __construct(
          Config $mediaConfig,
          Filesystem $filesystem
          )

          $this->mediaConfig = $mediaConfig;
          $this->filesystem = $filesystem;



          Now you can use this like,



           $directory = $this->filesystem->getDirectoryRead('media');
          $fullImagePath = $directory->getAbsolutePath($this->mediaConfig->getMediaPath($product->getThumbnail()));


          Where $product is your product object.






          share|improve this answer




















          • Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
            – Sammu Sundar
            Dec 20 '18 at 5:48


















          4














          A quick solution according to your tests:



          $fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();





          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f255223%2fhow-to-get-the-image-directory%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            First, inject below class in your constructor



             use MagentoCatalogModelProductMediaConfig;
            use MagentoFrameworkFilesystem;


            /**
            * @var Config
            */
            private $mediaConfig;

            /**
            * @var Filesystem
            */
            private $filesystem;


            /**
            * @param Config $mediaConfig
            * @param Filesystem $filesystem
            */
            public function __construct(
            Config $mediaConfig,
            Filesystem $filesystem
            )

            $this->mediaConfig = $mediaConfig;
            $this->filesystem = $filesystem;



            Now you can use this like,



             $directory = $this->filesystem->getDirectoryRead('media');
            $fullImagePath = $directory->getAbsolutePath($this->mediaConfig->getMediaPath($product->getThumbnail()));


            Where $product is your product object.






            share|improve this answer




















            • Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
              – Sammu Sundar
              Dec 20 '18 at 5:48















            2














            First, inject below class in your constructor



             use MagentoCatalogModelProductMediaConfig;
            use MagentoFrameworkFilesystem;


            /**
            * @var Config
            */
            private $mediaConfig;

            /**
            * @var Filesystem
            */
            private $filesystem;


            /**
            * @param Config $mediaConfig
            * @param Filesystem $filesystem
            */
            public function __construct(
            Config $mediaConfig,
            Filesystem $filesystem
            )

            $this->mediaConfig = $mediaConfig;
            $this->filesystem = $filesystem;



            Now you can use this like,



             $directory = $this->filesystem->getDirectoryRead('media');
            $fullImagePath = $directory->getAbsolutePath($this->mediaConfig->getMediaPath($product->getThumbnail()));


            Where $product is your product object.






            share|improve this answer




















            • Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
              – Sammu Sundar
              Dec 20 '18 at 5:48













            2












            2








            2






            First, inject below class in your constructor



             use MagentoCatalogModelProductMediaConfig;
            use MagentoFrameworkFilesystem;


            /**
            * @var Config
            */
            private $mediaConfig;

            /**
            * @var Filesystem
            */
            private $filesystem;


            /**
            * @param Config $mediaConfig
            * @param Filesystem $filesystem
            */
            public function __construct(
            Config $mediaConfig,
            Filesystem $filesystem
            )

            $this->mediaConfig = $mediaConfig;
            $this->filesystem = $filesystem;



            Now you can use this like,



             $directory = $this->filesystem->getDirectoryRead('media');
            $fullImagePath = $directory->getAbsolutePath($this->mediaConfig->getMediaPath($product->getThumbnail()));


            Where $product is your product object.






            share|improve this answer












            First, inject below class in your constructor



             use MagentoCatalogModelProductMediaConfig;
            use MagentoFrameworkFilesystem;


            /**
            * @var Config
            */
            private $mediaConfig;

            /**
            * @var Filesystem
            */
            private $filesystem;


            /**
            * @param Config $mediaConfig
            * @param Filesystem $filesystem
            */
            public function __construct(
            Config $mediaConfig,
            Filesystem $filesystem
            )

            $this->mediaConfig = $mediaConfig;
            $this->filesystem = $filesystem;



            Now you can use this like,



             $directory = $this->filesystem->getDirectoryRead('media');
            $fullImagePath = $directory->getAbsolutePath($this->mediaConfig->getMediaPath($product->getThumbnail()));


            Where $product is your product object.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 19 '18 at 15:26









            Keyur Shah

            12.8k23764




            12.8k23764











            • Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
              – Sammu Sundar
              Dec 20 '18 at 5:48
















            • Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
              – Sammu Sundar
              Dec 20 '18 at 5:48















            Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
            – Sammu Sundar
            Dec 20 '18 at 5:48




            Thank you for your answer . it saves my time . i need one more clarification if $product->getThumbnail() returns null. Then how do i get the default image
            – Sammu Sundar
            Dec 20 '18 at 5:48













            4














            A quick solution according to your tests:



            $fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();





            share|improve this answer

























              4














              A quick solution according to your tests:



              $fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();





              share|improve this answer























                4












                4








                4






                A quick solution according to your tests:



                $fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();





                share|improve this answer












                A quick solution according to your tests:



                $fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 19 '18 at 14:18









                PЯINCƏ

                7,68621136




                7,68621136



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f255223%2fhow-to-get-the-image-directory%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?