pack to gz and return archive file download
function pack($dir){ $dir = realpath($dir); $phar = new PharData($dir.'.tar'); $phar->buildFromDirectory($dir); $phar->compress(Phar::GZ); header('Content-Type: application/x-gzip'); header('Content-Disposition: attachment; filename="'.pathinfo($dir.'.tar.gz', PATHINFO_BASENAME).'"'); echo file_get_contents($dir.'.tar.gz'); }