Php 强制下载后Codeigniter重定向
我有一个下载JSON文件的公共函数。我希望它在下载完成后重定向到索引(Php 强制下载后Codeigniter重定向,php,codeigniter,Php,Codeigniter,我有一个下载JSON文件的公共函数。我希望它在下载完成后重定向到索引(base\u url)。我尝试使用ob\u start和ob\u flushPHP函数,但没有成功。这可能吗 $this->load->helper('url'); $data['events'] = $this->events_model->get_events(); ob_start(); header("Content-Description: File Tran
base\u url
)。我尝试使用ob\u start
和ob\u flush
PHP函数,但没有成功。这可能吗
$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());
函数redirect()在“echo”之后不起作用
重定向之前,您无法在浏览器中回显任何内容
请评论这一行:
//echo json_encode($data);
您检查过了吗?您不能在同一HTTP响应中传递下载数据和重定向。