title: Download TAR through PHP
body: <p>I need to download all files in a directory so I started by creating a (non-gziped) tar of all those files. This tar is valid and can be accessed correctly on the server but unfortunately, I can't seem to download it correctly through PHP. I get an error saying 'Unknown or corrupt image file!' when I try to open the downloaded tar file.</p>
  
  <p>Here's my php file:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  
  &lt;?php
    $filename = '/path/to/my.tar';
  
    header( 'Content-type: archive/tar' );
    header( 'Content-Disposition: attachment; filename="' . basename( $filename ) . '"'  );
    header( 'Content-Transfer-Encoding: binary' );
    header( 'Content-Length: ' . filesize( $filename ) );
    readfile( $filename );
  ?&gt;
  </code></pre>
  
  <p>Also, I've tried a few different header variations for eg:</p>
  
  <pre><code>header( 'Content-type: application/x-tar' );
  header( 'Content-type: application/force-download' );
  </code></pre>
  
  <p>I have the same problem regardless. Out of ideas....</p>