1

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 – Gopal Patel Feb 15 '17 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 Feb 15 '17 at 5:59
0

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));
    //print_r($csv);
    array_walk($csv, function(&$a) use ($csv) {
      $a = array_combine($csv[0], $a);
    });
    array_shift($csv); # remove column header
    //print_r($csv);
    
    
    foreach($csv as $key=>$img){
        //echo $img['IMAGE'];
         $import_location = 'uploads';
        $file_target = $import_location."/".basename($img['IMAGE']);
    
        $image = file_get_contents($img['IMAGE']);
    file_put_contents($file_target,$image);  
    
        /* if(!empty($img)){
            $my_image = file_get_contents($img);
            file_get_contents(filename)
    
            $filename = $data[0] . ".jpg";
             echo $filename. "\n";
            if(!file_exists($filename))
                {
                    $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, privacy policy and cookie policy

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