Php 将数组输出到csv
我正在尝试将数据从阵列输出到csv并下载它 我正在使用基于zend框架的社交引擎Php 将数组输出到csv,php,zend-framework,csv,socialengine,fputcsv,Php,Zend Framework,Csv,Socialengine,Fputcsv,我正在尝试将数据从阵列输出到csv并下载它 我正在使用基于zend框架的社交引擎 public function indexAction() { $this->outputCSV(); //$this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('passport_admin_main', a
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
您正在使用两种不同的路径:
readfile('spreadsheet/OutOfArea.csv');
^^^^^^^^^^^^
$fp = fopen('OutOfAreaReport.csv', 'w');
^----no path
您是否已直接在服务器上检查该文件?“OutofareReport.csv”此文件的正确访问权限是什么。它是否应为$fp=fopen('spreadsheet/OutofareReport.csv','w')@Kasiagolek遗憾的是,这不起作用。您是否直接在服务器上检查了该文件?“outofeareareport.csv”此文件的正确访问权限是什么。它是否应该是$fp=fopen('spreadsheet/outofeareareport.csv','w')@不幸的是,这是一个很好的众调试示例:)与CroudSource相反这是一个很好的众调试示例:)与CroudSource相反