octobercms/october · error · SystemException

: failed to open stream for export: No such file or…

Error message

{$path}: failed to open stream for export: No such file or directory.

What it means

Thrown when @fopen on the export savePath fails (returns false instead of a resource), meaning PHP could not create/open the CSV export file for writing. Despite the 'No such file or directory' wording, this fires whenever fopen returns non-resource: the target directory does not exist, the path is wrong, or the web server user lacks write permission.

Solutions

  1. Create the destination directory (mkdir -p) before exporting and ensure the web server user can write to it
  2. Check that the 'savePath' export option points to an absolute, valid path with a writable parent directory
  3. If filesystem writes are not possible, run the export with the 'useOutput' option so the CSV streams to the browser instead of being saved
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/backend/models/exportmodel/EncodesCsv.php:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/7676ce0678b0c4fe. Report an issue: GitHub.

Appendix: source

Thrown at modules/backend/models/exportmodel/EncodesCsv.php:125

        }

        // Add records
        foreach ($results as $result) {
            $data = $this->matchDataToColumns($result, $columns);
            $csv->insertOne($data);
        }

        // Output
        if ($options['useOutput']) {
            $csv->output($options['fileName']);
            return;
        }

        // Save to file
        if ($path = $options['savePath']) {
            $resource = @fopen($path, 'w+');
            if (!is_resource($resource)) {
                throw new SystemException("{$path}: failed to open stream for export: No such file or directory.");
            }
            foreach ($csv->chunk(8192) as $chunk) {
                fwrite($resource, $chunk);
            }
            fclose($resource);
            return;
        }

        return $csv->toString();
    }
}

View on GitHub (pinned to b608633a7e)