First you need to get the csv file where you add into folder directory
$uri = "myfile.csv";
The below code used to read the csv file content where $uri is the path of you csv file.
$count is used to get teh file data for initials to last element block.
$mydata = array();
if (($handle = fopen($uri, "r")) !== FALSE)
{
$count=0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($count!=0)
{
$mydata['id'][] =$data[0]; // id of category array
$mydata['name'][] =$data[1];// name array
// and add array as you like field in csv file.
}
$count++;
}
}
the output of above code will make a array of 'id' and 'name' associated with the array unique key.
foreach($mydata['id'] as $key=>$catdata)
{
echo $name = $mydata['name'][$key];
//you can get the name of category associate with the key field
// to add the category in magento here you go
$category = Mage::getModel('catalog/category');
$category->setStoreId(0);
$categoryName = $name;
$rootCategory['name'] = $categoryName;
$rootCategory['path'] = "1/2";
//$rootCategory['display_mode'] = "PRODUCTS";
$rootCategory['is_active'] = 1;
$category->addData($rootCategory);
try
{
$category->save();
$CategoryId = $category->getId();
}
catch (Exception $e)
{
echo "categories not found";
}
}
I hope this post will help you : thankyou