PHP Headers - Content & Location
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4373440/download-a-file-and-redirect-or-alternative">Download a file and redirect&hellip;or alternative</a>  </p>
</blockquote>



<p>Basically, we have a PHP file which outputs a file type using PHP headers.</p>

<p>We want it to work like this:</p>

<p>User clicks link, page opens, download prompt comes up and then the page that prompted the download (the main php page) redirects to another page...</p>

<p>How can I go about doing this? I want it to only redirect once the download prompt has been delivered to the user.</p>

<p>So.. sort of a thank you page.</p>

<p>Can this be done like so:</p>

<pre><code>header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public', false);
header('Content-Description: File Transfer');
header('Content-Type: '.$type);
header('Accept-Ranges: bytes');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
/* sleep for say 3 seconds.. */
header('Location: thankyou.php');
exit();
</code></pre>

<p>This code was purely written as an example, but how can we create something like this?</p>

<p>So the download prompt pops up, wait say 3 seconds, and then direct the origin page to a thank you page.</p>
