title: PHP ZIP file download
body: <p>Here is a code which downloads attachment files from the an imap server. Almost all file types (pdf, doc, xls, etc) are being downloaded correctly, where as some zip files give the following error:</p>
  
  <p>"The archive is either in unknown format or damaged"</p>
  
  <p>Code:</p>
  
  <pre><code>//data from imap server
  $name = "xyz 123.zip";
  $type = "APPLICATION";
  $subtype = "ZIP";
  $encoding = "BASE64";
  $body = imap_base64($data);
  
  header('Content-Description: File Transfer');
  header('Content-Type: '. $type .'/'. $subtype);
  header('Content-Disposition: attachment; filename='.$name);
  header('Content-Transfer-Encoding: '.$encoding);
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  ob_clean();
  flush();
  echo $body;
  </code></pre>
  
  <p>Also if I echo the data and convert it to a file using:</p>
  
  <p><a href="http://www.motobit.com/util/base64-decoder-encoder.asp" rel="nofollow">http://www.motobit.com/util/base64-decoder-encoder.asp</a></p>
  
  <p>The file is being downloaded correctly. Hence no problem in getting the file from server.
  Where am I going wrong??</p>