0

I am trying to output data from an array to a csv and download it.

I am using social engine which is built on zend framework.

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);
    }
}

At the moment it downloads the CSV but it has no values in the CSV it is empty.

4

1 回答 1

3

您正在使用两种不同的路径:

    readfile('spreadsheet/OutOfArea.csv');
              ^^^^^^^^^^^^

    $fp = fopen('OutOfAreaReport.csv', 'w');
                 ^----no path
于 2012-08-15T15:45:59.307 回答