How to get the image directory
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
add a comment |
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
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
image magento2.2.6 directory
asked Dec 19 '18 at 14:13
Sammu Sundar
779
779
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
A quick solution according to your tests:
$fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
A quick solution according to your tests:
$fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();
add a comment |
A quick solution according to your tests:
$fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();
add a comment |
A quick solution according to your tests:
$fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();
A quick solution according to your tests:
$fullPath = $this->directorylist->getPath("media").'/catalog/product'.$product->getThumbnail();
answered Dec 19 '18 at 14:18
PЯINCƏ
7,68621136
7,68621136
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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