How To Export product with Category Names in Magento

<?php
ini_set(‘memory_limit’, ‘2048M’);
ini_set(‘max_execution_time’, 180000);

require_once ‘../app/Mage.php’;
umask(0);

// output headers so that the file is downloaded rather than displayed
header(‘Content-Type: text/csv; charset=utf-8’);
header(‘Content-Disposition: attachment; filename=products.csv’);
// create a file pointer connected to the output stream
$output = fopen(‘php://output’, ‘w’);

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel(‘admin/user’);
$userModel->setUserId(0);

$collection = Mage::getModel(‘catalog/product’)
->getCollection()
->addAttributeToSelect(‘*’);

$attributeSetModel = Mage::getModel(“eav/entity_attribute_set”);

// $product->getModel(),$product->getProductcode(), //ColorCombination Material

foreach($collection as $product) {
$_cat = array();
$categoryName = array();

foreach ($product->getCategoryIds() as $Id) {
$_cat = Mage::getModel(‘catalog/category’)->setStoreId(Mage::app()->getStore()->getId())->load($Id);
$categoryName[] = $_cat->getName();
}
$categoryNameList = implode(“,”, $categoryName);

fputcsv($output, array(
$product->getId(),
$product->getSku(),
$product->getName(),
$product->getPrice(),
$product->getCommissionForProduct(),
$product->getDisplaySize(),
$product->getAttributeText(‘manufacturer’),
$product->getModelName(),
$product->getSuppliar(),
$product->getStatus(),
$categoryNameList
)
);
}
?>