protected 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.

Parameters

array $data:

Return value

array

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

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php, line 125

Class

FileBag
FileBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

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