Skip to content

Commit 7914d95

Browse files
daumfabpot
authored andcommitted
[HttpFoundation] UploadedFile: Added ability to the original extension of the file uploaded
1 parent 58cb6f5 commit 7914d95

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ public function getClientOriginalName()
118118
return $this->originalName;
119119
}
120120

121+
/**
122+
* Returns the original file extension
123+
*
124+
* It is extracted from the original file name that was uploaded.
125+
* Then is should not be considered as a safe value.
126+
*
127+
* @return string The extension
128+
*/
129+
public function getClientOriginalExtension()
130+
{
131+
return pathinfo($this->originalName, PATHINFO_EXTENSION);
132+
}
133+
121134
/**
122135
* Returns the file mime type.
123136
*

src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public function testGetClientOriginalName()
8989
$this->assertEquals('original.gif', $file->getClientOriginalName());
9090
}
9191

92+
public function testGetClientOriginalExtension()
93+
{
94+
$file = new UploadedFile(
95+
__DIR__.'/Fixtures/test.gif',
96+
'original.gif',
97+
'image/gif',
98+
filesize(__DIR__.'/Fixtures/test.gif'),
99+
null
100+
);
101+
102+
$this->assertEquals('gif', $file->getClientOriginalExtension());
103+
}
104+
105+
92106
/**
93107
* @expectedException Symfony\Component\HttpFoundation\File\Exception\FileException
94108
*/

0 commit comments

Comments
 (0)