【问题标题】:Codeigniter redirect after force download [duplicate]强制下载后Codeigniter重定向[重复]
【发布时间】:2013-04-02 09:55:35
【问题描述】:

我有一个下载 JSON 文件的公共函数。我希望它在下载完成后重定向到索引 (base_url)。我尝试使用ob_startob_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());

【问题讨论】:

  • 你检查过this吗?
  • 您不能在同一个 HTTP 响应中传送下载数据重定向。

标签: php codeigniter


【解决方案1】:

'echo' 后函数 redirect() 不起作用;

重定向之前,您无法在浏览器中回显任何内容

请评论此行:

//echo json_encode($data);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-24
    • 2011-07-31
    • 2013-12-19
    • 2012-07-17
    • 2011-08-30
    • 1970-01-01
    • 2018-05-06
    • 2012-08-03
    相关资源
    最近更新 更多