title: Codeigniter: download file and redirect
body: <p>I have a form on this page <a href="http://www.obsia.com/products/thassos_wonder_brochure/" rel="nofollow">http://www.obsia.com/products/thassos_wonder_brochure/</a>
  On hitting submit, I want it start downloading the file and also get redirected to thank you page. But I can only get it either download the file or redirect or load the thank for downloading page.</p>
  
  <p>This is the function for checking the form and submiting:</p>
  
  <pre><code>function thassos_wonder_brochure()
  {
      $this-&gt;load-&gt;helper('form');
      $this-&gt;load-&gt;helper('email');
      $this-&gt;load-&gt;library('email');
      $this-&gt;load-&gt;library('form_validation');
  
      //form validation
      $this-&gt;form_validation-&gt;set_rules('firstname', 'First Name', 'required|max_length[32]');
      $this-&gt;form_validation-&gt;set_rules('lastname', 'Last Name', 'required|max_length[32]');
      $this-&gt;form_validation-&gt;set_rules('companyemail', 'Company Email', 'required|max_length[100]|valid_email|unique');
  
      $this-&gt;load-&gt;model('brochure_model');
      if ($this-&gt;form_validation-&gt;run() == FALSE) 
      {
          // redisplay user form and repopulate fields
          $this-&gt;load-&gt;view('/tw/thassos_wonder_brochure_view');
      }   
      //display confirmation web page and send email
      else
      {   
  
          if($query = $this-&gt;brochure_model-&gt;addContact())
          {
              redirect('/thankyou/thassos_wonder_download');  (UPDATE)    
          }   
      }
  
  }
  </code></pre>
  
  <p>Below is the code is on the thank you page ending with redirect to the download page: (UPDATE)</p>
  
  <pre><code>    &lt;?php $this-&gt;load-&gt;view('header_view.php'); ?&gt;
      &lt;div class="prod"&gt;
      &lt;?php $this-&gt;load-&gt;view('pmenu_view');?&gt;
  
  &lt;div class="product_desc" id="tw_download"&gt;
      &lt;h1&gt;Thank you for Downloading&lt;/h1&gt;
      &lt;p&gt;You have downloaded the brochure for ThassosWonder - for white stones specifically. You will also receive further information and link to the downloads in your email after you click on the confirmation link in your email.&lt;/p&gt;
      &lt;?php echo br(1); ?&gt;
      &lt;p&gt;Feel free to write to us, if you are unable &lt;?php echo anchor('contact', 'to get desired finish from your white marble or stones')?&gt;. You can upload a picture to get a thorough analysis from our Research Director.&lt;/p&gt;
      &lt;br /&gt;
  
  &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php $this-&gt;load-&gt;view('footer_view');?&gt;  
  &lt;?php redirect('download/thassos_wonder_brochure'); ?&gt;
  </code></pre>
  
  <p>This is the code I used on the download page. How can I download the file and also redirect it to thank you page.</p>
  
  <pre><code>&lt;?php 
  $this-&gt;load-&gt;helper('download');
  $name = 'ThassosWonder.pdf';
  $data = file_get_contents("./downloads/brochures/Thassos_Wonder_Obsia.pdf"); // Read the file's contents - cannot use relative path. It will try to call the file from same directory (controller) as this file. In order for it get the contents from the root folder put a . in front of the relative path//
  force_download($name, $data); 
   ?&gt;
  </code></pre>
  
  <p>Any help would be deeply appreciated.</p>