{"record":{"id":"060fb579b8ea8fa8","repo":"getgrav/grav","slug":"failed-to-rename-file-bad-destination","errorCode":null,"errorMessage":"Failed to rename file: Bad destination","messagePattern":"Failed to rename file: Bad destination","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"error","filePath":"system/src/Grav/Common/Media/Traits/MediaUploadTrait.php","lineNumber":401,"sourceCode":"    public function renameFile(string $from, string $to, ?array $settings = null): void\n    {\n        // Add the defaults to the settings.\n        $settings = $this->getUploadSettings($settings);\n        $filesystem = Filesystem::getInstance(false);\n\n        // This method had no filename validation at all. It has no callers in core\n        // today, but it is part of the public MediaUploadInterface, so a plugin can\n        // reach it directly. Both names are checked the same way deleteFile() does.\n        if (!$this->checkFilepath($from) || !Utils::checkFilename($filesystem->basename($from))\n            || !$this->checkFilepath($to) || !Utils::checkFilename($filesystem->basename($to))) {\n            // TODO: translate error message\n            throw new RuntimeException('Failed to rename file: ' . $this->translate('PLUGIN_ADMIN.BAD_FILENAME'), 400);\n        }\n\n        $path = $settings['destination'] ?? $this->getPath();\n        if (!$path) {\n            // TODO: translate error message\n            throw new RuntimeException('Failed to rename file: Bad destination', 400);\n        }\n\n        /** @var UniformResourceLocator $locator */\n        $locator = $this->getGrav()['locator'];\n        $locator->clearCache();\n\n        // Get base name of the file.\n        $pathname = $filesystem->pathname($from);\n\n        // Remove @2x, @3x and .meta.yaml\n        [$base, $ext,,] = $this->getFileParts($filesystem->basename($from));\n        $from = \"{$pathname}{$base}.{$ext}\";\n\n        [$base, $ext,,] = $this->getFileParts($filesystem->basename($to));\n        $to = \"{$pathname}{$base}.{$ext}\";\n\n        $this->doRename($from, $to, $path);\n","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php#L383-L419","documentation":"Error \"Failed to rename file: Bad destination\" thrown in getgrav/grav.","triggerScenarios":"Thrown at system/src/Grav/Common/Media/Traits/MediaUploadTrait.php:401 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}