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\HttpFoundationCode
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;
}