We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Form with Image input: problem with hasFiles function

Found another problems.

I have a Form with a file Input. When I submit the form without selecting a file, it's sent as if there is a "empty file", so the hasFiles and getUploadedFiles both return true/array of empty file.

So when I save my model, the image path is always changed, event if I don't want to (as It pass through my hasFiles condition).

Add a check with isUploadedFile , work fine for me

edited Dec '17

I think this is a known problem - at least it's one I've heard of before. Rather than checking if($Request->hasFiles()), you can use if($Request->getUploadedFiles() > 0).

It's certainly not ideal, but it works.

Edit: I meant you could use if(count($Request->getUploadedFiles()) > 0



8.2k

@Dylan it doens't works for me. As I said I alway have an array in $Request->getUploadedFiles() but the properties are empty/0, so I can't really cheack with that.

@corentin I'll try that.

For now I made a "dirty" check that control if the size property is > 0.

I mis-typed my suggestion. I've updated my answer.