Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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) {
...


38.6k
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.