Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Form.php

function Form::getPhpFiles

Gets the file field values as PHP.

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does. The returned array is consistent with the array for field values (For a compound file field foo[bar] it will create foo[bar][name], instead of foo[name][bar] which would be found in $_FILES.

See also

getPhpValues), rather than uploaded files found in $_FILES.

File

vendor/symfony/dom-crawler/Form.php, line 146

Class

Form
Form represents an HTML form.

Namespace

Symfony\Component\DomCrawler

Code

public function getPhpFiles() : array {
    $values = [];
    foreach ($this->getFiles() as $name => $value) {
        $qs = http_build_query([
            $name => $value,
        ], '', '&');
        if ($qs) {
            parse_str($qs, $expandedValue);
            $varName = substr($name, 0, \strlen(key($expandedValue)));
            array_walk_recursive($expandedValue, function (&$value, $key) {
                if (ctype_digit($value) && ('size' === $key || 'error' === $key)) {
                    $value = (int) $value;
                }
            });
            reset($expandedValue);
            $values[] = [
                $varName => current($expandedValue),
            ];
        }
    }
    return array_replace_recursive([], ...$values);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal