title: php header download redirect
body: <p>I'm making a file sharing site for the fun. Trying to make it so that when I hit download, it starts the download. Instead of just a link to <code>/files/$file</code> im trying to do a header redirect:</p>
  
  <p><b>download.php</b></p>
  
  <pre><code>/**
  * File Download
  */
  
  $query = mysql_query("SELECT id,name,desc FROM files WHERE id = ".intval($_GET['id']));
  $row = mysql_fetch_assoc($query);
  
  $file = $row['name'];
  
  if (file_exists($file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($file));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
  }
  
  ?&gt;
  
  Filename: &lt;?=$row['name']?&gt;
  Desc: &lt;?=$row['desc']?&gt;
  
  &lt;a href="#"&gt;Download this file&lt;/a&gt;
  </code></pre>
  
  <p>Im stuck here, what should I do next?</p>
  
  <p>thank you</p>