title: PHP: how to tar folder and send directly to client using passthru?
body: <p>I can directly download database dump using:</p>
  
  <pre><code>$filename = $database . '-' . date("d-m-Y_(G_i_s)") . ".sql.gz";
  $mime = "application/x-gzip";
  
  
  header("Content-Type: " . $mime);
  header('Content-Disposition: attachment; filename="' . $filename . '"');
  
  
  $cmd = "mysqldump --opt -h $host -u $username -p$password $database";
  
  
  passthru($cmd);
  exit(0);
  </code></pre>
  
  <p>Can I do it with .tar file make from directory? Just generate file and download it, without saving on server?</p>
  
  <p>I can execute this (and file is correct):</p>
  
  <pre><code>exec('tar -czf /path/download/backup.tar.gz /path/download/');
  </code></pre>
  
  <p>But I don't want to store backup file on server... I want to download it directly.
  I tried to do something like my database dump example... but without success.</p>
  
  <p>Any ideas how to do it?</p>
  
  <p>EDIT:</p>
  
  <p>Thanks for help. Removing -f was good idea.</p>
  
  <p>Now it works:</p>
  
  <pre><code>$filename = 'download-' . date("d-m-Y_(G_i_s)") . ".tar.gz";
  $mime = "application/x-tgz";
  
  
  header("Content-Type: " . $mime);
  header('Content-Disposition: attachment; filename="' . $filename . '"');
  $cmd = "tar -cz " . $_SERVER['DOCUMENT_ROOT'] . "/download/";
  
  passthru($cmd);
  exit(0);
  </code></pre>