{"record":{"id":"912b41ea269e289a","repo":"BookStackApp/BookStack","slug":"failed-to-add-files-for-zip-export-received-error","errorCode":null,"errorMessage":"Failed to add files for ZIP export, received error: ","messagePattern":"Failed to add files for ZIP export, received error: ","errorType":"exception","errorClass":"ZipExportException","httpStatus":null,"severity":"error","filePath":"app/Exports/ZipExports/ZipExportBuilder.php","lineNumber":107,"sourceCode":"\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) {\n                unlink($file);\n            }\n            foreach ($addedNames as $name) {\n                $zip->deleteName($name);\n            }\n            $zip->close();\n            unlink($zipFile);\n            throw new ZipExportException(\"Failed to add files for ZIP export, received error: \" . $exception->getMessage());\n        }\n\n        $zip->close();\n\n        foreach ($toRemove as $file) {\n            unlink($file);\n        }\n\n        return $zipFile;\n    }\n}\n","sourceCodeStart":89,"sourceCodeEnd":119,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Exports/ZipExports/ZipExportBuilder.php#L89-L119","documentation":"ZipExportException thrown in ZipExportBuilder::build when extracting/adding the export's attachment/image files to the archive fails; partial files already added are removed from the zip before throwing. The underlying error comes from the files->extractEach callback (e.g. missing or unreadable source file on disk).","triggerScenarios":"Thrown at app/Exports/ZipExports/ZipExportBuilder.php:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the storage/uploads files referenced by the export still exist on disk","Verify read permissions on uploaded file storage","Inspect the wrapped exception's error text for the specific file that failed","Re-upload missing attachments then retry the export"],"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"}