diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 2194c178aee7e..a94fd93c5f73e 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -114,6 +114,10 @@ public function getContent(): string protected function getTargetFile(string $directory, ?string $name = null): self { + if (is_file($directory)) { + throw new FileException(\sprintf('The path "%s" is a file and it was expected to be a directory.', $directory)); + } + if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) { throw new FileException(\sprintf('Unable to create the "%s" directory.', $directory));