getgrav/grav · error · RuntimeException
Failed to rename file: Bad destination
Error message
Failed to rename file: Bad destination
What it means
Error "Failed to rename file: Bad destination" thrown in getgrav/grav.
Source
Thrown at system/src/Grav/Common/Media/Traits/MediaUploadTrait.php:401
public function renameFile(string $from, string $to, ?array $settings = null): void
{
// Add the defaults to the settings.
$settings = $this->getUploadSettings($settings);
$filesystem = Filesystem::getInstance(false);
// This method had no filename validation at all. It has no callers in core
// today, but it is part of the public MediaUploadInterface, so a plugin can
// reach it directly. Both names are checked the same way deleteFile() does.
if (!$this->checkFilepath($from) || !Utils::checkFilename($filesystem->basename($from))
|| !$this->checkFilepath($to) || !Utils::checkFilename($filesystem->basename($to))) {
// TODO: translate error message
throw new RuntimeException('Failed to rename file: ' . $this->translate('PLUGIN_ADMIN.BAD_FILENAME'), 400);
}
$path = $settings['destination'] ?? $this->getPath();
if (!$path) {
// TODO: translate error message
throw new RuntimeException('Failed to rename file: Bad destination', 400);
}
/** @var UniformResourceLocator $locator */
$locator = $this->getGrav()['locator'];
$locator->clearCache();
// Get base name of the file.
$pathname = $filesystem->pathname($from);
// Remove @2x, @3x and .meta.yaml
[$base, $ext,,] = $this->getFileParts($filesystem->basename($from));
$from = "{$pathname}{$base}.{$ext}";
[$base, $ext,,] = $this->getFileParts($filesystem->basename($to));
$to = "{$pathname}{$base}.{$ext}";
$this->doRename($from, $to, $path);
View on GitHub (pinned to 6040efed04)
When it happens
Trigger: Thrown at system/src/Grav/Common/Media/Traits/MediaUploadTrait.php:401 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of getgrav/grav@6040efed04 (2026-08-17).
Data as JSON: /api/errors/060fb579b8ea8fa8.
Report an issue: GitHub.