1

I added enctype="multipart/form-data" In the form with the input fields for files or images.

Please, can you help me review my codes and why I have this error message issue below on trying to upload and submit a file form? :

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

I'm thinking the issue could be from my database structure.

I have included the link to my controller, template and MySQL file in GitHub.

https://github.com/olaolu20077

In "newprojectz" controller file and other necessary files.

Thank you.

I added enctype="multipart/form-data" In the form with the input fields for files or images.

I expected graphics files are array of string and making my form field a multi part attributes would help in both array and string form input submission.

3
  • While trying to change the code to: $postImage = $this->request->getData () I then got this error message: Call to a member function getClientFilename () on array" Don't know if to call the data as a string or an array? Commented Aug 18, 2024 at 12:41
  • I can't tell you that, you need to look into that function getClientFilename() to see how it should be called. I don't know what IDE you're using but usually if you press an hold on Ctrl btn and click on the function name, it will jump to the function itself where you can see this kind of information. Commented Aug 18, 2024 at 16:08
  • Okay, really appreciate. Commented Aug 18, 2024 at 17:19

1 Answer 1

1

the error you're getting "Call to a member function getClientFilename () on string" is actually telling you all you need.

having looked in your code:

in your controller you're calling getData() like this:

$data = $this->request->getData(); (I don't know how the result looks like but looking at the next like I'd say you get an aray structure where ['picture'] is an string, probably the filename, so it would be nice to have a var_dump($data) to see what the result is)

$fileObject = $data['picture'];

but than in here: $fileObject->getClientFilename();

you're trying to get the filename like an object and this is causing the error.

I've never worked with cakePHP but I guess $fileObject should be written like this: $fileObject = $data; instead of $fileObject = $data['picture'];

lots of assumptions here, so please provide some debug infos like the var_dump :)

Sign up to request clarification or add additional context in comments.

2 Comments

I would work around that and get back to you.
While trying to change the code to: $postImage = $this->request->getData () I then got this error message: Call to a member function getClientFilename () on array" Don't know if to call the data as a string or an array? –

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.