Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:35:11+00:00 2026-05-28T07:35:11+00:00

I have this in my controller: function foo() { // my code redirect(site_url(‘competitor/main’), ‘refresh’);

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:35:11+00:00Added an answer on May 28, 2026 at 7:35 am

    Codeigniter’s redirect() function exits after sending the location header. So, call the function before redirecting.

    $this->foo2();
    redirect('competitor/main', 'refresh');
    

    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.

    header("Refresh:0;url=".site_url('competitor/main')); 
    $this->foo2();
    exit;
    

    When user upload file on site_url('competitor/main') it will go to foo() function then redirect immediately back to competitor/main page and foo2() will run in background process.

    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:

    • Upload to another URL, process the file, then redirect to the page of your choice (with a status message if you wish)
    • Have your upload form post to an <iframe>, which will keep the page in it’s current state.
    • Advanced: Use javascript to upload the file with an XMLHttpRequest/AJAX. There are a number of scripts available for this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a controller function with these lines: $this->load->view('stdHeader_view'); echo <div class='main'>;
I have this function on my controller (Im using CodeIgniter) that reads the database,
In our code we used to have something like this: *(controller->bigstruct) = ( struct
I have this code in my controller and want to test this code line
i have this controller function: Public Function Index(ByVal id As System.Nullable(Of Integer)) As ActionResult
I have this controller function that returns cpu stats: public ActionResult GetStats() { Random
I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public
I have this in my controller. I need my view to generate some HTML,
I have this in my controller: MyTestViewModel asdf = new MyTestViewModel { SomeTestDate =
I have this command in a Rails controller open(source) { |s| content = s.read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.