2013-04-10 93 views
0

我有一個公共功能下載JSON文件。我希望在下載完成後重定向到索引(base_url)。我嘗試使用ob_startob_flush PHP函數,但那不行。這可能嗎?強制下載後的Codeigniter重定向

$this->load->helper('url'); 
    $data['events'] = $this->events_model->get_events(); 

    ob_start(); 
    header("Content-Description: File Transfer"); 
    header("Content-Type: application/octet-stream"); 
    header("Content-Disposition: attachment; filename='EVENTS.json'"); 

    echo json_encode($data); 
    ob_flush(); 

    redirect(base_url()); 
+0

你檢查,[這](http://stackoverflow.com/questions/822707/ PHP-生成文件換版,然後重定向)? – user1190992 2013-04-10 14:05:34

+1

您無法在相同的HTTP響應中提供下載數據_and_重定向。 – CBroe 2013-04-10 14:15:01

回答

0

函數redirect()在'echo'後不起作用;

之前重定向你不能迴響在瀏覽器中的任何

請評論該行:

//echo json_encode($data);