title: PHP Downloading File(s) outside webroot
body: <p>I save many documents outside the webroot.  </p>
  
  <p>I want to click a link, that opens a new window (target="_blank"), and force download the file that's found.</p>
  
  <p>Here's what I've got so far, but my results show gobble-de-gook in the browser popup, rather than forcing the download to the desktop:</p>
  
  <pre><code>function download($filelocation){
  
    $filename = basename($filelocation); 
    if (file_exists($filelocation)) {
      header('Content-Description: File Transfer');
      header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment; filename='.$filename); 
      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($filelocation));
      ob_clean();
      flush();
      readfile($filelocation);
      exit;
    }
  
  }
  </code></pre>
  
  <p>In the new browser window I simply call that <code>download()</code> function with a specific path the the file.</p>
  
  <p>It's definitely finding the file, but now I'm just wondering what I'm missing with header() to force the file through the browser.</p>