Latest news
Home » SocialEngine » How to make a csv file in php socialengine

How to make a csv file in php socialengine

public function downloadcsvAction()
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout();
$query=Engine_Db_Table::getDefaultAdapter()->select()
->from(‘engine4_users’,array(‘user_id’,’email’,’displayname’,’level_id’,’enabled’,’approved’,’creation_date’))
->where(‘user_id !=?’,1)
->where(‘user_id not in (?)’, array(‘685′,’870′,’948′,’965′,’1031′,’1249′,’1279′,’1283’));
$aResult= $query->query()->fetchAll();
header(‘Content-Type: application/csv’);
header(‘Content-Disposition: attachement; filename=”users.csv”‘);
$f = fopen(‘php://output’, ‘w’) or show_error(“Can’t open php://output”);
$n = 0;$line = array();$array=array();
$line[]=’Email’;  $line[]=’Display Name’;
$array[]=$line;
$line[]=’info@smarttips.in’;$line[‘sijo’];
$array[] = $line;
}
foreach ($array as $user)
{
$n++;
if (!fputcsv($f, $user))
{
show_error(“Can’t write line $n: $user”);
}
}
fclose($f) or show_error(“Can’t close php://output”);
}

Leave a Reply

x

Check Also

Pass custom error message to zend/socialengine form from controller

$this->view->form = $form = new User_Form_Admin_Universities_Createdomain(); $this->view->university_id = $iId = $this->_getParam(‘id’, null); $form->populate(array(‘university_id’=>$iId)); if($this->getRequest()->isPost() && ...