I want to save a simple product programatically.I have used the following link http://inchoo.net/magento/programming-magento/programatically-manually-creating-simple-magento-product/

All fields are saved except image. The image url is from an external link as (for example) http://test12.net/test/public/uploads/shanks/shank-for-test-2.png

I want to copy the image and save as product image .Please help.

  • first save that image in media/catalog/product/import folder then provide that path Commented Feb 15, 2017 at 5:37
  • I am not able to copy the image from url and save it to media/catalog/product/import path. Please guide me.
    – Vindhuja
    Commented Feb 15, 2017 at 5:59

1 Answer 1


Enter code here`Please follow below steps:-

  1. Create one "imgs2.csv" with the column name of "IMAGE" (assign all external images URLs) put the same on Magento root directory.

  2. Create one new directory "uploads" on Magento root directory.

  3. Create a file with name "download_img.php" on Magento root directory and following code in the same file, after you hit the same file on website URLs for example http://www.example.com/download_img.php

    $csv = array_map('str_getcsv', file($file));
    array_walk($csv, function(&$a) use ($csv) {
      $a = array_combine($csv[0], $a);
    array_shift($csv); # remove column header
    foreach($csv as $key=>$img){
        //echo $img['IMAGE'];
         $import_location = 'uploads';
        $file_target = $import_location."/".basename($img['IMAGE']);
        $image = file_get_contents($img['IMAGE']);
        /* if(!empty($img)){
            $my_image = file_get_contents($img);
            $filename = $data[0] . ".jpg";
             echo $filename. "\n";
                    $my_file = fopen($filename,'w+');
                    file_put_contents($filename, $my_image);
                    echo $filename . "\n";
            $image = "/uploads/" . $filename;
            echo $image . "\n"; */

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.