I have a code which
ZipArchive::addGlob()
But it seems the addGlobe()
is not enough fast and files are deleted before addGlob()
creates the zip file.
Code looks like:
function saveCsvDaysDataZip($campaign_id)
{
$tempDirName = CampaignsDeviceDays::CSV_REPORTS_DIR . '/' . $campaign_id . '/temp';
$zip = new ZipArchive();
$zip->open($tempDirName . 'reports.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$addGlob = $zip->addGlob("$tempDirName/*", GLOB_BRACE, ['remove_all_path' => TRUE]);
if( $addGlob === false ) throw new \Exception("CampaignsDeviceDays::saveCsvDaysDataZip() error: \$zip->addGlobe() failed. " . $this->zipArchive->getStatusString() );
}
public function removeCsvExportsDir($campaign_id)
{
$dirName = self::CSV_REPORTS_DIR . '/' . $campaign_id . '/temp';
FileSystem::delete($dirName);
}
$saveCsvDaysDataZip($campaign_id);
$removeCsvExportsDir($campaign_id);
Is it possible that removeCsvExportsDir($campaign_id)
is called before addGlob()
is done?
Your function had no call to ZipArchive::close
- which I guess PHP will then take as "permission" to continue populating the ZIP archive in the background, and return before that process is actually finished.