Cannot get uploaded files on Cakephp 4

What am I missing when I try to get uploaded files in my controller? If I debug PHP native $_FILES “superglobal” I can get all the upload file information there. There is no error.

But in CakePHP post data I get empty data in posted “file” field. It’s mind boggling and I cannot find out what to debug… Is there some logic conditions when Cake discards file input (but it is fine on PHP side)?

I may need to use PHP $_FILES soon (build my own logic) but there should be fine functions in CakePHP for this so it is a shame…

Check this

1 Like

Thanks, I have read that. But the problem is that file information is empty in data… $_FILES works as I described earlier. What might be the reason?

$request->getUploadedFiles() is returning nothing? I can’t remember if maybe Cake is more strict about what form types it will extract files from than the HTTP spec. Remember that Cake code is just PHP code, so you can look at what getUploadedFiles returns, then look for where that gets initialized, and see what conditions there may be around that. It’s all debuggable!

1 Like

Make sure that you have include enctype attribute into form declaration like below

echo $this->Form->create(null, ['id'=>'myForm','role' => 'form','enctype'=>'multipart/form-data']);

1 Like

@Hareshpatel Yes, thanks. I have this. And PHP side works fine.

@Zuluru, thanks! I’ll do that - I’m sure debugging will reveal something… But it has to wait when I have more time for that…