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

Breadcrumb

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

function FileBag::fixPhpFilesArray

Fixes a malformed PHP $_FILES array.

PHP has a bug that the format of the $_FILES array differs, depending on whether the uploaded file fields had normal field names or array-like field names ("normal" vs. "parent[child]").

This method fixes the array to look like the "normal" $_FILES array.

It's safe to pass an already converted array, in which case this method just returns the original array unmodified.

1 call to FileBag::fixPhpFilesArray()
FileBag::convertFileInformation in vendor/symfony/http-foundation/FileBag.php
Converts uploaded files to UploadedFile instances.

File

vendor/symfony/http-foundation/FileBag.php, line 99

Class

FileBag
FileBag is a container for uploaded files.

Namespace

Symfony\Component\HttpFoundation

Code

protected function fixPhpFilesArray(array $data) : array {
    $keys = array_keys($data + [
        'full_path' => null,
    ]);
    sort($keys);
    if (self::FILE_KEYS !== $keys || !isset($data['name']) || !\is_array($data['name'])) {
        return $data;
    }
    $files = $data;
    foreach (self::FILE_KEYS as $k) {
        unset($files[$k]);
    }
    foreach ($data['name'] as $key => $name) {
        $files[$key] = $this->fixPhpFilesArray([
            'error' => $data['error'][$key],
            'name' => $name,
            'type' => $data['type'][$key],
            'tmp_name' => $data['tmp_name'][$key],
            'size' => $data['size'][$key],
        ] + (isset($data['full_path'][$key]) ? [
            'full_path' => $data['full_path'][$key],
        ] : []));
    }
    return $files;
}

API Navigation

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