checkPassword($_SESSION["mainconf_password"])) { $exporter = new ConfigDataExporter(); if (!headers_sent()) { header('Content-Type: application/zip; charset=utf-8'); header('Content-disposition: attachment; filename=lam-config.zip'); } try { $zip = new ZipArchive(); $zipTmpFile = tmpfile(); if ($zipTmpFile === false) { throw new LAMException(_('Unable to create temporary file.')); } $metaData = stream_get_meta_data($zipTmpFile); if (empty($metaData['uri'])) { throw new LAMException(_('Unable to create temporary file.')); } $zipFile = $metaData['uri']; fclose($zipTmpFile); $zip->open($zipFile, ZipArchive::CREATE); $json = $exporter->exportAsJson(); $zip->addFromString('lam-config.json', $json); $zip->close(); $handle = fopen($zipFile, "r"); if ($handle === false) { throw new LAMException(_('Unable to create temporary file.')); } $fileSize = filesize($zipFile); if (($fileSize === false) || ($fileSize <= 0)) { throw new LAMException(_('Unable to create temporary file.')); } $contents = fread($handle, $fileSize); fclose($handle); unlink($zipFile); echo $contents; } catch (LAMException $e) { logNewMessage(LOG_ERR, $e->getTitle() . ' ' . $e->getMessage()); } exit; } echo $_SESSION['header']; printHeaderContents(_("Import and export configuration"), '../..'); ?>