我正在尝试将数据从数组输出到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中没有值,因此它是空的。
答案 0 :(得分:3)
您正在使用两种不同的路径:
readfile('spreadsheet/OutOfArea.csv');
^^^^^^^^^^^^
$fp = fopen('OutOfAreaReport.csv', 'w');
^----no path