Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rishabh1994's avatar

Call to a member function getClientOriginalName() on string

Getting this error while uploading image. Can anybody help me with this error???

0 likes
5 replies
36864's avatar

Not if you don't share some code we can't.

Does the error get thrown in your controller, model or view? Post the relevant code.

konstantinrachev's avatar

Probably you are just not calling getClientOriginalExtension() on request('file') (or whatever your file input name is equal to), but on a string instead, as it is mentioned into the posted error.

gator's avatar

The file is not getting uploaded:

  1. Make sure you have enctype="multipart/form-data" on the input form.
  2. Check if file is, in fact, getting uploaded using:
if ($request->hasFile('image')) {
    
}
AddWebContribution's avatar

Try code like:

if(Input::file('image')->isValid())
{
    $extension = Input::file('image')->getClientOriginalExtension();
    .
    .
    .
}

Hope this work for you!

ModestasV's avatar

I'm pretty sure you are getting an array of files when your system expects to get a single file. This happened to me and my customers multiple times due to the crashed javascript file. This literally causes javascript to halt ajax uploads of files and passes multi-file array to the system.

Please or to participate in this conversation.