I creating a product pro grammatically in magento2. The issue is that i can't set addImageToMediaGallery. I always receive error:

The file "/home/xxx/pub/media/tmp/catalog/product/t/e/test.jpg" doesn't exist or not a file

My picture locating in /pub/media/testimg/test.jpg media folder and has 777 permissions and files has same perms. Here is a code:

$dir = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');
    $dir->getPath('media') . '/testimg/test.jpg',

so it looks like the system found the image but can't copy in tmp folder ? please help.

2 Answers 2


Try this

sudo chmod -R 775 var/tmp/ pub/media/

You will not change any template files , you can give permission in pub/media folder. You will get.

sudo chmod -R 777 var/ media/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.