@@ -201,22 +201,22 @@ public function move(string $directory, ?string $name = null): File
201201
202202 switch ($ this ->error ) {
203203 case \UPLOAD_ERR_INI_SIZE :
204- throw new IniSizeFileException ($ this ->getErrorMessage ());
204+ throw new IniSizeFileException ($ this ->getExceptionMessage ());
205205 case \UPLOAD_ERR_FORM_SIZE :
206- throw new FormSizeFileException ($ this ->getErrorMessage ());
206+ throw new FormSizeFileException ($ this ->getExceptionMessage ());
207207 case \UPLOAD_ERR_PARTIAL :
208- throw new PartialFileException ($ this ->getErrorMessage ());
208+ throw new PartialFileException ($ this ->getExceptionMessage ());
209209 case \UPLOAD_ERR_NO_FILE :
210- throw new NoFileException ($ this ->getErrorMessage ());
210+ throw new NoFileException ($ this ->getExceptionMessage ());
211211 case \UPLOAD_ERR_CANT_WRITE :
212- throw new CannotWriteFileException ($ this ->getErrorMessage ());
212+ throw new CannotWriteFileException ($ this ->getExceptionMessage ());
213213 case \UPLOAD_ERR_NO_TMP_DIR :
214- throw new NoTmpDirFileException ($ this ->getErrorMessage ());
214+ throw new NoTmpDirFileException ($ this ->getExceptionMessage ());
215215 case \UPLOAD_ERR_EXTENSION :
216- throw new ExtensionFileException ($ this ->getErrorMessage ());
216+ throw new ExtensionFileException ($ this ->getExceptionMessage ());
217217 }
218218
219- throw new FileException ($ this ->getErrorMessage ());
219+ throw new FileException ($ this ->getExceptionMessage ());
220220 }
221221
222222 /**
@@ -265,7 +265,7 @@ private static function parseFilesize(string $size): int|float
265265 /**
266266 * Returns an informative upload error message.
267267 */
268- public function getErrorMessage (): string
268+ private function getExceptionMessage (): string
269269 {
270270 static $ errors = [
271271 \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
283283
284284 return sprintf ($ message , $ this ->getClientOriginalName (), $ maxFilesize );
285285 }
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+ }
286298}
0 commit comments