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

Phalcon4 didn't get Guzzle file request.

Hi, there.

Well, I make 2 server (Front-End server / File server).

  1. browser at post file to Front-End server with form. (is work)

    // "getFile" is my custom function, it is using $this->request->getUploadedFiles()
    $params['file'] = $this->getFile('file'); // file data
  2. Front-End server at post file to File server whit Guzzle.

    self::$guzzle->post($url, [
            'multipart' => [
                [
                    'name' => 'file',
                    'filename' => $params['file']->getName(),
                    'contents' => fopen($params['file']->getTempName(), 'r'),
                ]
            ]
        ]);
  3. File server
    $this->request->getUploadedFiles(); // empty
    $this->request->hasFiles(); // true
    $_FILES // file data (is same data to no.1)

So, I want get file data to $this->request->getUploadedFiles();.

How can i get file data to $this->request->getUploadedFiles();?

*Sorry about my EN skill is not good :(



8.4k

$this->request->getUploadedFiles(); should return an array of Phalcon\Http\Request\File instances and it uses the super global $_FILES

if the return value of $this->request->getUploadedFiles(); is an empty array turn on the error reporting

error_reporting(E_ALL);

$this->request->getUploadedFiles();

if nothing is changed dump the contents of $_FILES here

edited Dec '20

$this->request->getUploadedFiles(); should return an array of Phalcon\Http\Request\File instances and it uses the super global $_FILES

if the return value of $this->request->getUploadedFiles(); is an empty array turn on the error reporting

error_reporting(E_ALL);

$this->request->getUploadedFiles();

if nothing is changed dump the contents of $_FILES here

I tracking all errors.

try {
            $app = (new Application(self::$di))->handle($URI);
            $app->send();
        } catch (\Throwable $e) {
            $router = self::$di->get("response");

            if (IS_DEBUG) { // env setting value
                error_reporting(E_ALL);
                throw new \Exception($e->getMessage());
            } else {
                ini_set('display_errors', 0);
                error_reporting(0);

                if($URI != "/error"){
                    $router->redirect('/error')->send();
                }
            }
        }

But, no any error message. (env setting value is "true")

Guzzle post option is multipart/form-data.

$_FILES data is here

array (size=5)
      'name' => string '3066.jpg' (length=8)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string '/tmp/phpfyYfhQ' (length=14)
      'error' => int 0
      'size' => int 486215


8.4k

Notices and Warnings won't be caught under Throwable

just to make sure that silly errors ( i'm not sure its the case ) won't affect the code let the errors to be shown in your index.php (error_reporting(E_ALL);)

can you dump $this->request->getUploadedFiles();

i can't really see anything that could result in something like this and i checked the source code of Phalcon\Http\Request::getUploadedFiles()

edited Dec '20

Notices and Warnings won't be caught under Throwable

just to make sure that silly errors ( i'm not sure its the case ) won't affect the code let the errors to be shown in your index.php (error_reporting(E_ALL);)

can you dump $this->request->getUploadedFiles();

i can't really see anything that could result in something like this and i checked the source code of Phalcon\Http\Request::getUploadedFiles()

I added error_reporting(E_ALL); in my index.php.

But, no any message.

$this->request->getUploadedFiles(); data is

array (size=0)
          empty

I really have a question.

$this->request->hasFiles() is return true.

But, way $this->request->getUploadedFiles(); is empty?

file server controller

if($this->isPost() == true){
            $params['type'] = $this->request->getPost('type');
            $params['file'] = $this->request->getUploadedFiles();

            $test = [
                "type" => $params['type'],
                "file-phalcon" => $params['file'],
                "file-default" => $_FILES['file'],
                "has-file" => $this->request->hasFiles(),
            ];

            var_dump($test);
        }

response

array (size=4)
  'type' => string 'private' (length=7)
  'file-phalcon' => 
    array (size=1)
      0 => 
        array (size=0)
          empty
  'file-default' => 
    array (size=5)
      'name' => string '1719749.jpg' (length=11)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string '/tmp/phpJAWEqB' (length=14)
      'error' => int 0
      'size' => int 579304
  'has-file' => boolean true


8.4k

this is weird

$params['file'] = $this->request->getUploadedFiles(); this shouldn't return an array with an empty array

the only thing i can think of is that the service named request is overridden

can you do another test

$request = new \Phalcon\Http\Request;

var_dump($request->hasFiles());

var_dump($request->getUploadedFiles());

if that is not the issue i'm afraid i have nothing else to give

this is weird

$params['file'] = $this->request->getUploadedFiles(); this shouldn't return an array with an empty array

the only thing i can think of is that the service named request is overridden

can you do another test

$request = new \Phalcon\Http\Request;

var_dump($request->hasFiles());

var_dump($request->getUploadedFiles());

if that is not the issue i'm afraid i have nothing else to give

I try that, but nothing changed.

I think it is missing when using 'getUploadedFiles' in file interface with convert $_FILE to Phalcon file interface.

Well, I just using $_FILES. Thanks to answer my question.