I can directly download database dump using:
$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);
Can I do it with .tar file make from directory? Just generate file and download it, without saving on server?
I can execute this (and file is correct):
exec('tar -czf /path/download/backup.tar.gz /path/download/');
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.
Any ideas how to do it?
EDIT:
Thanks for help. Removing -f was good idea.
Now it works:
$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);