Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_image.php
Go to the documentation of this file.
1 <?php
8 
11 $mediaConfig = $objectManager->get(\Magento\Catalog\Model\Product\Media\Config::class);
12 
14 $mediaDirectory = $objectManager->get(\Magento\Framework\Filesystem::class)
15  ->getDirectoryWrite(DirectoryList::MEDIA);
16 $targetDirPath = $mediaConfig->getBaseMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/m/a/');
17 $targetTmpDirPath = $mediaConfig->getBaseTmpMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/m/a/');
20 
21 $targetTmpFilePath = $mediaDirectory->getAbsolutePath() . DIRECTORY_SEPARATOR . $targetTmpDirPath
22  . DIRECTORY_SEPARATOR . 'magento_image.jpg';
23 copy(__DIR__ . '/magento_image.jpg', $targetTmpFilePath);
24 // Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
$targetTmpFilePath
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$objectManager
$targetTmpDirPath
$targetDirPath
$mediaDirectory
$mediaConfig