{"record":{"id":"16911c6aa8b8b421","repo":"BookStackApp/BookStack","slug":"failed-to-create-zip-file-for-export","errorCode":null,"errorMessage":"Failed to create zip file for export.","messagePattern":"Failed to create zip file for export\\.","errorType":"exception","errorClass":"ZipExportException","httpStatus":null,"severity":"error","filePath":"app/Exports/ZipExports/ZipExportBuilder.php","lineNumber":81,"sourceCode":"\n    /**\n     * @throws ZipExportException\n     */\n    protected function build(): string\n    {\n        $this->references->buildReferences($this->files);\n\n        $this->data['exported_at'] = date(DATE_ATOM);\n        $this->data['instance'] = [\n            'id'      => setting('instance-id', ''),\n            'version' => AppVersion::get(),\n        ];\n\n        $zipFile = tempnam(sys_get_temp_dir(), 'bszip-');\n        $zip = new ZipArchive();\n        $opened = $zip->open($zipFile, ZipArchive::OVERWRITE);\n        if ($opened !== true) {\n            throw new ZipExportException('Failed to create zip file for export.');\n        }\n\n        $zip->addFromString('data.json', json_encode($this->data));\n        $zip->addEmptyDir('files');\n\n        $toRemove = [];\n        $addedNames = [];\n\n        try {\n            $this->files->extractEach(function ($filePath, $fileRef) use ($zip, &$toRemove, &$addedNames) {\n                $entryName = \"files/$fileRef\";\n                $zip->addFile($filePath, $entryName);\n                $toRemove[] = $filePath;\n                $addedNames[] = $entryName;\n            });\n        } catch (\\Exception $exception) {\n            // Cleanup the files we've processed so far and respond back with error\n            foreach ($toRemove as $file) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Exports/ZipExports/ZipExportBuilder.php#L63-L99","documentation":"ZipExportException thrown in ZipExportBuilder::build when ZipArchive::open on the temporary export file (created with tempnam) does not return true, meaning PHP could not initialize the zip archive for writing. Usually points to temp directory permission problems or a missing/failed ZipArchive extension.","triggerScenarios":"Thrown at app/Exports/ZipExports/ZipExportBuilder.php:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check sys_get_temp_dir() is writable by the PHP process","Verify the PHP zip extension (php-zip) is installed and enabled","Check disk space on the temp filesystem","Retry the export after fixing the environment"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}