$zipname = storage_path() . '/' . 'zipName.zip';
$zip = new \ZipArchive;
if ($zip->open($zipname, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) != true) {
throw new \Exception('Can\'t save zip file');
}
$columns = ['id', 'uid', 'name', 'dob'];
$clientCvs = fopen('php://temp/maxmemory:1048576', 'w');
if (false === $clientCvs) {
throw new \Exception('Failed to create temporary file');
}
fputcsv($clientCvs, $columns);
fputcsv($clientCvs, [
$this->id,
$this->uid,
$this->name,
$this->dob ?? '-',
]);
rewind($clientCvs);
$zip->addFromString('member.csv', stream_get_contents($clientCvs));
fclose($clientCvs);