0

I try to get $request->image->getClientOriginalName() but it returns

"Call to a member function getClientOriginalName() on string"

When I call $request->image it returns a string of the image name on my disk like picture.png

How to get a file object?!

2
  • Can you share more details about your form? Commented Aug 31, 2018 at 7:26
  • @NicoHaase I forget to add enctype="multipart/form-data" on my form declaration . Commented Aug 31, 2018 at 9:02

3 Answers 3

4

First, your form need to have enctype="multipart/form-data" in it. Make sure it looks like this:

<form action="your/path" method="post" enctype="multipart/form-data">

Then check that your input has type="file":

<input type="file" name="image">

Then access your file in your controller via:

$request->file('image')->getClientOriginalName();
Sign up to request clarification or add additional context in comments.

1 Comment

oh , i have no idea how i forgot (enctype="multipart/form-data") thanks ^^
0

You could use:

$request->file('image')->getClientOriginalName();

Comments

0

I would suggest going through this link; which gives an in depth overview of how handling files from requests work in laravel.

Although you can always do the below:

$file = $request->file('photo');

or

$file = $request->photo;

I would suggest you going through the documentation and changing the version of laravel as per your needs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.