$tmp_file = tmpfile(); $tmp_file_path = stream_get_meta_data($tmp_file)['uri']; $zip = new ZipArchive; $res = $zip->open($tmp_file_path, ZipArchive::CREATE); foreach ($ptah_p7s->Signs as $i => $sign) { $zip->addFromString("signature{$i}.p7s", base64_decode($sign)); } $zip->close(); header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="download.zip"'); echo(file_get_contents($tmp_file_path));