title: Force Download via Ajax and PHP
body: <p>i want to create a downloadscript which allows Force Download of JPGs.
  This is my php script:</p>
  
  <pre><code>&lt;?php
      header("Pragma: public"); // required
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Description: File Transfer");
      header("Content-Type: image/jpg");
      header('Content-Disposition: attachment; filename="'.basename($GET['a']).'"');
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: ".filesize(($GET['a']));
      readfile(($GET['a']);
  ?&gt;
  </code></pre>
  
  <p>This is a code segment of my js code:</p>
  
  <pre><code>function downloadFile(a){
      document.location = "download.php?a="+ a;
  }
  </code></pre>
  
  <p>With this code sample nothing happens. If i append the result into a HTML-tag, it shows the content of the file.</p>
  
  <p>Any ideas how to teach the browser to download this file?</p>
  
  <p><strong>EDIT: SCRIPT UPDATE</strong></p>