You are here

protected function FileBag::fixPhpFilesArray in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/FileBag.php \Symfony\Component\HttpFoundation\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 vendor/symfony/http-foundation/FileBag.php
Converts uploaded files to UploadedFile instances.

File

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

Class

FileBag
FileBag is a container for uploaded files.

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 ($data['name'] as $key => $name) {
    $files[$key] = $this
      ->fixPhpFilesArray(array(
      'error' => $data['error'][$key],
      'name' => $name,
      'type' => $data['type'][$key],
      'tmp_name' => $data['tmp_name'][$key],
      'size' => $data['size'][$key],
    ));
  }
  return $files;
}