open($t, ZipArchive::CREATE); foreach($file_list as $f) { $z->addFile($f, preg_replace('/^.*?patterns\//', '', $f)); } $z->close(); header('Content-type: application/zip'); header(sprintf('Content-Disposition: attachment; filename="%s.zip"', $type)); echo(file_get_contents($t)); ?>