Laravel get name of file
- To get the file name, as mentioned in the docs:
You may access uploaded files that are included with the Illuminate\Http\Request instance using the file method. The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo class and provides a variety of methods for interacting with the file
There are a variety of other methods available on UploadedFile instances. Check out the API documentation for the class for more information regarding these methods.
So you can use this method: getClientOriginalName()
$request->file('input_pdf')->getClientOriginalName();
Would return the file name.
You can do this to check if the file exists before calling any methods on it:
if ($request->hasFile('input_pdf')) { return $request->file('input_pdf')->getClientOriginalName();} else { return 'no file!'}
- To solve the issue of
dd($request->file('input_pdf'))
returningnull
check you are using the correct name for the file. You can trydd($request)
and you will see if there are any files in it. You can check the file name when reviewing the dump of theRequest
object.
I think you forget to add
enctype="multipart/form-data"
In your form. Or if you used laravel HTML service provider use
{!! Form::open(array('files' => true)) !!}