I have this in my controller:
function foo() {
// my code
redirect(site_url('competitor/main'), 'refresh');
$this->foo2();
}
function foo2() {
// upload a file
}
How do I keep foo2() running after using the redirect() method?
The reason I want to call foo2() after redirect() is because I want to save upload time. When a user uploads a file at site_url('competitor/main') it will go to foo() function, then redirect immediately back to competitor/main page and foo2() will run in the background.
Codeigniter’s
redirect()functionexits after sending the location header. So, call the function before redirecting.Note: No need for
site_url()here, the redirect function will add it if you use a relative URL.I’m not sure what
foo2()does, but this looks a little iffy…If for some reason you can’t do that, then send the header with native PHP.
This probably isn’t the way to handle uploads, as you will have no way to deal with errors. There are a couple of other ways I can suggest:
<iframe>, which will keep the page in it’s current state.