BookStackApp/BookStack · error · ZipExportException

Failed to create zip file for export.

Error message

Failed to create zip file for export.

What it means

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.

Source

Thrown at app/Exports/ZipExports/ZipExportBuilder.php:81

    /**
     * @throws ZipExportException
     */
    protected function build(): string
    {
        $this->references->buildReferences($this->files);

        $this->data['exported_at'] = date(DATE_ATOM);
        $this->data['instance'] = [
            'id'      => setting('instance-id', ''),
            'version' => AppVersion::get(),
        ];

        $zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
        $zip = new ZipArchive();
        $opened = $zip->open($zipFile, ZipArchive::OVERWRITE);
        if ($opened !== true) {
            throw new ZipExportException('Failed to create zip file for export.');
        }

        $zip->addFromString('data.json', json_encode($this->data));
        $zip->addEmptyDir('files');

        $toRemove = [];
        $addedNames = [];

        try {
            $this->files->extractEach(function ($filePath, $fileRef) use ($zip, &$toRemove, &$addedNames) {
                $entryName = "files/$fileRef";
                $zip->addFile($filePath, $entryName);
                $toRemove[] = $filePath;
                $addedNames[] = $entryName;
            });
        } catch (\Exception $exception) {
            // Cleanup the files we've processed so far and respond back with error
            foreach ($toRemove as $file) {

View on GitHub (pinned to 18f8469a1c)

Solutions

  1. Check sys_get_temp_dir() is writable by the PHP process
  2. Verify the PHP zip extension (php-zip) is installed and enabled
  3. Check disk space on the temp filesystem
  4. Retry the export after fixing the environment
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at app/Exports/ZipExports/ZipExportBuilder.php:81 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BookStackApp/BookStack@18f8469a1c (2026-09-02). Data as JSON: /api/errors/16911c6aa8b8b421. Report an issue: GitHub.