title: PHP force download results in corrupted file
body: <p>I've got a PHP script that forces a download. Heres my code</p>
  
  <pre><code>//$file and $mime have been set earlier
  $basename = basename($file);
  $length   = sprintf("%u", filesize($file));
  header('Content-Description: File Transfer');
  header('Content-Type: '.$mime);
  header('Content-Disposition: attachment; filename="' . $basename . '"');
  header('Content-Transfer-Encoding: Binary');
  header('Connection: Keep-Alive');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . $length);
  set_time_limit(0);
  readfile($file);
  </code></pre>
  
  <p>Now this script works perfectly on my local server, but when I uploaded it to my site, and tried it out, the file downloaded (To test it i used an image), but when I opened it, i got <code>Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or is too large.</code></p>
  
  <p>I opened the file in Sublime Text, here's what it says
  <br />
  <b>Warning</b>:  set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in <b>/mounted-storage/home61c/sub001/sc38639-USWQ/www/test/scripts/download.php</b> on line <b>32</b><br />
  ‰PNG</p>
  
  <p>bla bla bla (I'm unable to copy and paste the stuff below it)</p>
  
  <p>What's going on?</p>