Skip to content

Laravel get name of file

In Laravel, you can use the getClientOriginalName() method to retrieve the original file name of an uploaded file. Here is an example of how to use it:

Example of getting name of file in Laravel

php
$file = $request->file('file');
$fileName = $file->getClientOriginalName();

<div class="alert alert-info flex not-prose"> Watch a course Learn object oriented PHP</div>

In this example, $file is the uploaded file and $fileName will contain the original file name. The file in $request->file('file') refers to the key of file in the $_FILES array.

Dual-run preview — compare with live Symfony routes.