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

Request hasFiles() returned "(int)2". Always.

Hi all!

Why

var_dump($this->request->hasFiles())

return

(int)2

Always. Even if the files do not exist.

it construction not work:

...
if($this->request->hasFiles() == true) {
...


77.7k
Accepted
answer

The method name is a bit misleading, the return type is not boolean but long. Also, you can pass in a boolean argument to limit the count to successful files.

https://github.com/phalcon/cphalcon/blob/7cd81ef3c04f660f2d901aa285c051ec8f44c0a1/phalcon/http/request.zep#L629

Try this:

public function someAction() {
    if($this->request->hasFiles(true)>0) {
        // yay
    } else {
        // nay
    }
}

thanks, Lajos.