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() not detecting file upload

I am attempting to check to see whether the user of my application has uploaded a file upon registration. I have set the form enctype to multipart in my form:

<form class="col-md-3" action="create" method="POST" enctype="multipart/form-data">

In the CreateController I am doing the following, just to test the $request->hasFiles() method. I have placed this at the head of the method.

if($this->request->hasFiles()) {
        print 'File uploaded';
        exit;
}

It's never true, even if a file is uploaded. I have also tried to var_dump($_FILES) and there seems to be nothing there too.

Any ideas what could be going wrong here?

When post_max_size is exceeded ' $_POSTand$_FILES` are empty on Apache not on Nginx, what I do:

if ($this->request->hasFiles()) {
    //...
}
else {
    if ((! empty ($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) ||
        (empty ($_POST) && empty ($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0)) {
        // Clear errors
        while (ob_get_level() > 0) {
            ob_end_clean();
        }

        $this->appendMessage(__(
            'Uploaded file exceeds the maximum upload size allowed {0}',
            [human_size(php_size_to_bytes(ini_get('post_max_size')))]
        ));
    }
    else {
        $this->appendMessage(__('No files uploaded'));
    }
}

That was the problem :) Thank you sir.