How to get product image path by prodct id in magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
2
down vote
favorite
Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be acheived ? please explain
thanks
Adarsh Shukla
magento2 image
|
show 1 more comment
up vote
2
down vote
favorite
Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be acheived ? please explain
thanks
Adarsh Shukla
magento2 image
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago
|
show 1 more comment
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be acheived ? please explain
thanks
Adarsh Shukla
magento2 image
Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be acheived ? please explain
thanks
Adarsh Shukla
magento2 image
magento2 image
edited 2 days ago
Sukumar Gorai
5,5873527
5,5873527
asked 2 days ago
Adarsh Shukla
3710
3710
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago
|
show 1 more comment
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago
|
show 1 more comment
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
To get media absolute path you can try below code.
public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList
) {
$this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
$mediaAbsoluteUrl = $this->directory->getPath('media');
}
I hope it'll work for you.
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
add a comment |
up vote
2
down vote
Add this below code in your file :
protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)
{
.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................
}
public function yourFunction()
{
$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
add a comment |
up vote
2
down vote
You can get product image path from below code
$product_id=20; //enter product id here
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
i Hope it help
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
|
show 2 more comments
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
To get media absolute path you can try below code.
public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList
) {
$this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
$mediaAbsoluteUrl = $this->directory->getPath('media');
}
I hope it'll work for you.
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
add a comment |
up vote
1
down vote
accepted
To get media absolute path you can try below code.
public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList
) {
$this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
$mediaAbsoluteUrl = $this->directory->getPath('media');
}
I hope it'll work for you.
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
To get media absolute path you can try below code.
public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList
) {
$this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
$mediaAbsoluteUrl = $this->directory->getPath('media');
}
I hope it'll work for you.
To get media absolute path you can try below code.
public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList
) {
$this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
$mediaAbsoluteUrl = $this->directory->getPath('media');
}
I hope it'll work for you.
edited 2 days ago
answered 2 days ago
Ramkishan Suthar
1,6541830
1,6541830
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
add a comment |
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
Will This give me product image path by product id ?
– Adarsh Shukla
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
it will written absolute path of media directory as per you mentioned in comments.
– Ramkishan Suthar
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
is my aim is to get products image by passing product id i am trying to display that image to admin grid
– Adarsh Shukla
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
You just need to append $product->getImage() after $mediaUrl
– Ramkishan Suthar
2 days ago
add a comment |
up vote
2
down vote
Add this below code in your file :
protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)
{
.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................
}
public function yourFunction()
{
$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
add a comment |
up vote
2
down vote
Add this below code in your file :
protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)
{
.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................
}
public function yourFunction()
{
$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
add a comment |
up vote
2
down vote
up vote
2
down vote
Add this below code in your file :
protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)
{
.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................
}
public function yourFunction()
{
$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}
Add this below code in your file :
protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)
{
.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................
}
public function yourFunction()
{
$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}
answered 2 days ago
Rohan Hapani
4,93021559
4,93021559
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
add a comment |
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
add a comment |
up vote
2
down vote
You can get product image path from below code
$product_id=20; //enter product id here
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
i Hope it help
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
|
show 2 more comments
up vote
2
down vote
You can get product image path from below code
$product_id=20; //enter product id here
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
i Hope it help
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
|
show 2 more comments
up vote
2
down vote
up vote
2
down vote
You can get product image path from below code
$product_id=20; //enter product id here
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
i Hope it help
You can get product image path from below code
$product_id=20; //enter product id here
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
i Hope it help
edited 2 days ago
answered 2 days ago
balwant
152215
152215
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
|
show 2 more comments
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
1
1
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog
– Adarsh Shukla
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
@AdarshShukla you mean media path?
– balwant
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
yes i wand to display image in admin grid i am using rendarar to get image
– Adarsh Shukla
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
@AdarshShukla check my updated code . $mediaUrl gives the path what you want
– balwant
2 days ago
|
show 2 more comments
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%2f250642%2fhow-to-get-product-image-path-by-prodct-id-in-magento-2%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
please refer to this link magento.stackexchange.com/questions/249393/…
– Ramkishan Suthar
2 days ago
hello sir thanks for reply but but i was looking for path not url
– Adarsh Shukla
2 days ago
plaease tell me how to do so
– Adarsh Shukla
2 days ago
ok you mean absolute path?
– Ramkishan Suthar
2 days ago
yes sir like var/www/magento/pub/media
– Adarsh Shukla
2 days ago