将数组输出到csv
问题描述:
我想从数组输出数据到csv并下载它。将数组输出到csv
我使用基于zend框架的社交引擎。
public function indexAction()
{
$this->outputCSV();
//$this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('passport_admin_main', array(), 'passport_admin_main_outofarea');
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
header('Content-Disposition: attachment; filename="OutOfAreaReport.csv"');
//content type
header('Content-type: application/excel');
//read from server and write to buffer
readfile('spreadsheet/OutOfArea.csv');
}
public function outputCSV(){
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('OutOfAreaReport.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
}
目前它下载CSV,但CSV中没有值是空的。
答
您使用两个不同的路径:
readfile('spreadsheet/OutOfArea.csv');
^^^^^^^^^^^^
$fp = fopen('OutOfAreaReport.csv', 'w');
^----no path
+1
这是CrowdDebugging的一个很好的例子:)而不是CroudSourcing – 2012-08-15 15:50:40
任何在你的错误日志? – wgcrouch 2012-08-15 15:34:47
不幸的是不是 – RSM 2012-08-15 15:43:58
你是否直接在服务器上检查过文件? – 2012-08-15 15:43:58