@@ -201,22 +201,22 @@ public function move(string $directory, ?string $name = null): File
201
201
202
202
switch ($ this ->error ) {
203
203
case \UPLOAD_ERR_INI_SIZE :
204
- throw new IniSizeFileException ($ this ->getErrorMessage ());
204
+ throw new IniSizeFileException ($ this ->getExceptionMessage ());
205
205
case \UPLOAD_ERR_FORM_SIZE :
206
- throw new FormSizeFileException ($ this ->getErrorMessage ());
206
+ throw new FormSizeFileException ($ this ->getExceptionMessage ());
207
207
case \UPLOAD_ERR_PARTIAL :
208
- throw new PartialFileException ($ this ->getErrorMessage ());
208
+ throw new PartialFileException ($ this ->getExceptionMessage ());
209
209
case \UPLOAD_ERR_NO_FILE :
210
- throw new NoFileException ($ this ->getErrorMessage ());
210
+ throw new NoFileException ($ this ->getExceptionMessage ());
211
211
case \UPLOAD_ERR_CANT_WRITE :
212
- throw new CannotWriteFileException ($ this ->getErrorMessage ());
212
+ throw new CannotWriteFileException ($ this ->getExceptionMessage ());
213
213
case \UPLOAD_ERR_NO_TMP_DIR :
214
- throw new NoTmpDirFileException ($ this ->getErrorMessage ());
214
+ throw new NoTmpDirFileException ($ this ->getExceptionMessage ());
215
215
case \UPLOAD_ERR_EXTENSION :
216
- throw new ExtensionFileException ($ this ->getErrorMessage ());
216
+ throw new ExtensionFileException ($ this ->getExceptionMessage ());
217
217
}
218
218
219
- throw new FileException ($ this ->getErrorMessage ());
219
+ throw new FileException ($ this ->getExceptionMessage ());
220
220
}
221
221
222
222
/**
@@ -265,7 +265,7 @@ private static function parseFilesize(string $size): int|float
265
265
/**
266
266
* Returns an informative upload error message.
267
267
*/
268
- public function getErrorMessage (): string
268
+ private function getExceptionMessage (): string
269
269
{
270
270
static $ errors = [
271
271
\UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB). ' ,
@@ -283,4 +283,16 @@ public function getErrorMessage(): string
283
283
284
284
return sprintf ($ message , $ this ->getClientOriginalName (), $ maxFilesize );
285
285
}
286
+
287
+ /**
288
+ * Retrieves a user-friendly error message for file upload issues, if any.
289
+ */
290
+ public function getErrorMessage (): string
291
+ {
292
+ if (\UPLOAD_ERR_OK === $ this ->error ) {
293
+ return '' ;
294
+ }
295
+
296
+ return $ this ->getExceptionMessage ();
297
+ }
286
298
}
0 commit comments