title: php download zip folder as attachment, folder is not found
body: <p>I'm at a bit of a loss as to why this folder is not being found. I have a script that, after searching a database to find the <code>$filename</code> of someone's purchase based on a stored random code, should simply return their file. My code looks like this (including the trailing end of the db query):</p>
  <pre><code>            $stmt_2 -&gt; bind_result($filename);
              $stmt_2 -&gt; fetch();
              $stmt_2 -&gt; close();
              
              // For .zip files
  
              $filepath='/media-files/Label/' . $filename;
  
              if (headers_sent()) {
                  echo 'HTTP header already sent';
              } else {
                  if (!is_file($filepath)) {
                      header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
                      echo 'File not found.';
                  } else if (!is_readable($filepath)) {
                      header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
                      echo 'File not readable.';
                  } else {
                      header('Content-Type: application/zip');
                      header('Content-Disposition: attachment; filename=&quot;' . basename($filepath) . '&quot;');
                      header('Content-Length: ' . filesize($filepath));
                      readfile($filepath);
                      exit;   
                  }
              }
  </code></pre>
  <p>When I run this code, I receive &quot;File not found.&quot; so <code>!is_file($filepath)</code> is where it is getting tripped up -- However, the path is correct and the zip is definitely there, so I'm not sure what is wrong here.</p>
  <p>In terms of debugging, I've tried removing the checks, going directly to the headers and readfile, which returns an empty zip folder. What does work is if I navigate directly to the file by URL...</p>
  <p><strong>UPDATE</strong>
  The file path issue has been fixed, but I am still not able to download the file. In all attempts I get either <code>ERR_INVALID_RESPONSE</code> or if I try to brute force download the file, it returns an empty file. I tried using these headers with no success:</p>
  <pre><code>header_remove(); 
  ob_end_clean();
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename=&quot;' . $filename . '&quot;');
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . filesize($filepath));
  readfile($filepath);
  ob_end_flush();
  exit;
  </code></pre>
  <p>They are large audio files, which appears to be causing the issue...</p>