File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
src/Symfony/Component/HttpFoundation Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -265,8 +265,14 @@ private static function parseFilesize(string $size): int|float
265265 /**
266266 * Returns an informative upload error message.
267267 */
268- public function getErrorMessage (): string
268+ public function getErrorMessage (): ? string
269269 {
270+ $ errorCode = $ this ->error ;
271+
272+ if ($ errorCode === \UPLOAD_ERR_OK ) {
273+ return null ;
274+ }
275+
270276 static $ errors = [
271277 \UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB). ' ,
272278 \UPLOAD_ERR_FORM_SIZE => 'The file "%s" exceeds the upload limit defined in your form. ' ,
@@ -277,7 +283,6 @@ public function getErrorMessage(): string
277283 \UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension. ' ,
278284 ];
279285
280- $ errorCode = $ this ->error ;
281286 $ maxFilesize = \UPLOAD_ERR_INI_SIZE === $ errorCode ? self ::getMaxFilesize () / 1024 : 0 ;
282287 $ message = $ errors [$ errorCode ] ?? 'The file "%s" was not uploaded due to an unknown error. ' ;
283288
Original file line number Diff line number Diff line change @@ -119,6 +119,18 @@ public function testErrorIsOkByDefault()
119119 $ this ->assertEquals (\UPLOAD_ERR_OK , $ file ->getError ());
120120 }
121121
122+ public function testErrorMessageIsNullIfErrorIsOk ()
123+ {
124+ $ file = new UploadedFile (
125+ __DIR__ .'/Fixtures/test.gif ' ,
126+ 'original.gif ' ,
127+ 'image/gif ' ,
128+ null
129+ );
130+
131+ $ this ->assertEquals (null , $ file ->getErrorMessage ());
132+ }
133+
122134 public function testGetClientOriginalName ()
123135 {
124136 $ file = new UploadedFile (
You can’t perform that action at this time.
0 commit comments