title: Php, error with readfile, downloaded files do not open
body: <p>I am using the following code to download files that are stored outside of the public folder.</p>
  
  <pre><code>  $mime_type = mime_content_type("{$_GET['file']}");
    define("IMG_LOC","/var/www/domain.com/upload/");
    $filename = $_GET['file'];
    header('Content-Description: File Transfer');
    header('Content-Type: '.$mime_type);
    header('Content-Disposition: attachment; filename='.basename(IMG_LOC.$filename));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    readfile($filename);
    exit;
  </code></pre>
  
  <p>The problem is, file downloaded using this script is not usable. Excel is opening empty, powerpoint tells "there is an error reading" and word tells its missing a converter. Whereas, if I download the same files using ftp and open them manually, the files open properly, showing that the files are not corrupt.</p>
  
  <p>For info, this is getting called from another page as : <code>file.php?file='. $filename</code></p>
  
  <p>Any help will be welcome. Thanks for your time.</p>