想要在下载完成时使用CodeIgniter加载页面


Want to load a page when downloads complete using CodeIgniter

我有一个控制器:-

function game_file($filename)
    {      
        $file_path = base_url()."resources/games_application/$filename";
        header('Content-Type: application/octet-stream');
        header("Content-Disposition: attachment; filename=$filename");
        ob_clean();
        flush();
        readfile($file_path);
        redirect('downloads');  //This is not working 
    }

我的观点是:-

<a href='".base_url()."downloads/game_file/".$games_data['file_name']."'>Download<a/>

我可以下载一个文件,但问题是下载后我想重定向到download控制器。这只会下载我的文件,但在下载完成后不会重定向。我做错什么了吗?

编辑:-我知道我无法重定向,因为标头已经发送,所以有人能帮我解决这个问题吗?

你的提议永远不会奏效。因为redirect()是一个标头操作,并且您已经设置了标头。但这本身只是一个问题。

您不能设置文件的下载,然后将页面重定向到其他地方!需要重新思考您的流程。也许可以在主下载页面上用javascript捕获"下载"操作。

但是你。。。redirect('downloads'); //This is not working永远不会工作。