Damaged File Download PHP
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13461417/download-php-is-always-damaged">download php is always damaged</a>  </p>
</blockquote>



<p>In my code, I can download a file but it mostly results in a damaged file etc. I am really stuck and has anyone any idea how I can improve my code. My images/documents are stored in the folder 'lessons'</p>

<p>They download and there is one image a 'png' which downloads perfectly, but uploading similar PNG files results in damaged files.</p>

<pre><code>    $cool = $_GET['id'];

   $sql = "SELECT id, type, name, size FROM upload WHERE id='$cool'";

 $result = mysql_query($sql, $db);
 $data = mysql_result($result, 0, "id");
 $name = mysql_result($result, 0, "name");
  $size = mysql_result($result, 0, "size");
  $type = mysql_result($result, 0, "type");

 header("Content-type: $type");
 header("Content-length: $size");
  header("Content-Disposition: attachment; filename=$name");
  header("Content-Description: PHP Generated Data");
 header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
ob_clean();
flush();
readfile($name);
exit();
</code></pre>
