如何在codeigniter中使用循环同时下载多个文件?

时间:2016-10-20 12:32:09

标签: php mysql codeigniter-3

这是我的代码:

    function download1() {
    $this->load->dbutil();
    $this->load->helper('file');
    $this->load->helper('download');
    $delimiter = ",";
    $newline = "\r\n";
    $filename = "filename_you_wish.csv";
    $query = $this->db->query("SELECT TABLE_NAME 
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='sample_db'");
    $res = $query->result_array();
    foreach ($res as $row):
        $filename = $row['TABLE_NAME'] . '.csv';
        $q = "select * from " . $row['TABLE_NAME'];
        $result = $this->db->query($q);
        $data = $this->dbutil->csv_from_result($result,$delimiter,$newline);
        force_download($filename, $data);
    endforeach;
    }

它只是下载第一个表而不再下载。我想要下载所有表格。

0 个答案:

没有答案