Skip to content

Commit e6d609c

Browse files
[8.x] Clarifies getClientOriginalName and getClientOriginalExtension methods (#7439)
* Clarifies `getClientOriginalName` and `getClientOriginalExtension` methods * Update filesystem.md * Update filesystem.md Co-authored-by: Taylor Otwell <[email protected]>
1 parent a324785 commit e6d609c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

filesystem.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,19 @@ If you are using the `storeAs` method, you may pass the disk name as the third a
397397
<a name="other-uploaded-file-information"></a>
398398
#### Other Uploaded File Information
399399

400-
If you would like to get the original name of the uploaded file, you may do so using the `getClientOriginalName` method:
400+
If you would like to get the original name and extension of the uploaded file, you may do so using the `getClientOriginalName` and `getClientOriginalExtension` methods:
401401

402-
$name = $request->file('avatar')->getClientOriginalName();
402+
$file = $request->file('avatar');
403403

404-
The `extension` method may be used to get the file extension of the uploaded file:
404+
$name = $file->getClientOriginalName();
405+
$extension = $file->getClientOriginalExtension();
405406

406-
$extension = $request->file('avatar')->extension();
407+
However, keep in mind that the `getClientOriginalName` and `getClientOriginalExtension` methods are considered unsafe, as the file name and extension may be tampered with by a malicious user. For this reason, you should typically prefer the `hashName` and `extension` methods to get a name and an extension for the given file upload:
408+
409+
$file = $request->file('avatar');
410+
411+
$name = $file->hashName(); // Generate a unique, random name...
412+
$extension = $file->extension(); // Determine the file's extension based on the file's MIME type...
407413

408414
<a name="file-visibility"></a>
409415
### File Visibility

0 commit comments

Comments
 (0)