1

I want to upload image by programmatically.

I have to imagefolder and i put it media/import/imagefolder. and My code is

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

 ini_set('display_errors', 1);
 ini_set('max_execution_time', 0);
 ini_set('memory_limit', '50024M');
$attrId = Mage::getSingleton('catalog/product')->getResource()->getAttribute('media_gallery')
->getAttributeId();
$path = Mage::getBaseDir('media').'\import'.DS;
echo $path;
$data = array();
echo "<br>";
echo "<pre>";
$files = glob($path.'*.jpg' ,  GLOB_BRACE);
//$path_parts = explode(".",$files);
    foreach($files as $key=>$value)   
    {  
        $filename = basename($value);
        //echo $filename;
        $path_parts = explode(".",$filename);

        unset($path_parts[1]);

        $data[] = array(
        'sku' => $path_parts[0],
        '_type' => 'simple',
        'status' => 1,
        'visibility' => 4,
        '_media_image'=> $value,
        '_media_attribute_id'=>$attrId,
        '_media_is_disabled' =>0,
        'image'=> $filename,
        'small_image'=> $filename,
        'thumbnail'=> $filename,

);
//$data = array_values($data);

    } print_r($data);
    try {
    /** @var $import AvS_FastSimpleImport_Model_Import */
    $import = Mage::getModel('fastsimpleimport/import');
    $import->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

echo "Check Now";

?>

but Image not uploaded.

so how can i do?

  • Is this on windows or linux? Also, is it finding any images at all? Are you getting any errors? – Sander Mangel Sep 8 '15 at 12:13
  • this is on windows and no one get error – ABC Sep 8 '15 at 12:26
  • Try to debug a little, does it find any images, is the image path valid etc. We have very little to go on – Sander Mangel Sep 8 '15 at 12:31
0

You need to use DS as directory spectator. not \

If you have using this then it must create issue in window & etc os.

$path = Mage::getBaseDir('media').'\import'.DS;

should be

$path = Mage::getBaseDir('media').DS.'import'.DS;

Mage::getBaseDir('media') =YourMagentoInstacePath/mediaFolder

0

There is a minor mistake and I changed this

$path = Mage::getBaseDir('media').'\import'.DS;

to

$path = Mage::getBaseUrl('media').'\import'.DS;
  • Mage::getBaseUrl('media') give the media url not media path...your answer is wrong – Amit Bera Sep 8 '15 at 16:28

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.