1717 *
1818 * @property-read string $name
1919 * @property-read string $sanitizedName
20+ * @property-read string $untrustedFullPath
2021 * @property-read string|null $contentType
2122 * @property-read int $size
2223 * @property-read string $temporaryFile
@@ -31,6 +32,7 @@ final class FileUpload
3132 public const IMAGE_MIME_TYPES = ['image/gif ' , 'image/png ' , 'image/jpeg ' , 'image/webp ' ];
3233
3334 private string $ name ;
35+ private string |null $ fullPath ;
3436 private string |false |null $ type = null ;
3537 private int $ size ;
3638 private string $ tmpName ;
@@ -47,6 +49,7 @@ public function __construct(?array $value)
4749 }
4850
4951 $ this ->name = $ value ['name ' ];
52+ $ this ->fullPath = $ value ['full_path ' ] ?? null ;
5053 $ this ->size = $ value ['size ' ];
5154 $ this ->tmpName = $ value ['tmp_name ' ];
5255 $ this ->error = $ value ['error ' ];
@@ -92,6 +95,19 @@ public function getSanitizedName(): string
9295 }
9396
9497
98+ /**
99+ * Returns the original full path as submitted by the browser during directory upload. Do not trust the value
100+ * returned by this method. A client could send a malicious directory structure with the intention to corrupt
101+ * or hack your application.
102+ *
103+ * The full path is only available in PHP 8.1 and above. In previous versions, this method returns the file name.
104+ */
105+ public function getUntrustedFullPath (): string
106+ {
107+ return $ this ->fullPath ?? $ this ->name ;
108+ }
109+
110+
95111 /**
96112 * Detects the MIME content type of the uploaded file based on its signature. Requires PHP extension fileinfo.
97113 * If the upload was not successful or the detection failed, it returns null.
0 commit comments