I have a function for export one csv file include all answers of each survey. I need one function for export all answers of all surveys (one survey per one csv file) into menory and zip it before download to computer
Not save all csv file into server or local storage, I need storage it into memory and zip it before download to computer
I had use this code:
function exportAllAnswer() {
allTokenId = getAllTokenId();
foreach(allTokend as $key->$value) {
exportAnswer($value->id, false);
}
$path = 'exportAllCsv';
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=allCsvs.zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
//change directory so the zip file doesnt have a tree structure in it.
chdir($path);
// zip the stuff (dir and all in there) into the tmp_zip file
exec('zip '.$tmp_zip.' *');
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
// clean up the tmp zip file
unlink($tmp_zip);
// delete folder csv
rmdir($path);
}