- To get the file name as indicated in the docs:
You can access the downloaded files that are included in 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 class SplFileInfo and provides many methods for interacting with the file
UploadedFile instances have many other methods. More information about these methods can be found in the API documentation for the class .
So you can use this method: getClientOriginalName()
http://api.symfony.com/3.0/Symfony/Component/HttpFoundation/File/UploadedFile.html#method_getClientOriginalName
$request->file('input_pdf')->getClientOriginalName();
Will return the file name.
You can do this to check if a 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 problem of returning
dd($request->file('input_pdf')) null , you are using the correct name for the file. You can try dd($request) and you will see if there are any files in it. You can check the file name when viewing the dump of the Request object.
source share