mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Convert FILES processing to use recursion.
Fixes issues with deeply nested file data issues. Fixes #2796
This commit is contained in:
parent
c15259f49c
commit
b54c3b0308
1 changed files with 25 additions and 15 deletions
|
@ -320,21 +320,31 @@ class CakeRequest implements ArrayAccess {
|
|||
|
||||
if (isset($_FILES['data'])) {
|
||||
foreach ($_FILES['data'] as $key => $data) {
|
||||
foreach ($data as $model => $fields) {
|
||||
if (is_array($fields)) {
|
||||
foreach ($fields as $field => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$this->data[$model][$field][$k][$key] = $v;
|
||||
}
|
||||
} else {
|
||||
$this->data[$model][$field][$key] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->data[$model][$key] = $fields;
|
||||
}
|
||||
}
|
||||
$this->_processFileData('', $data, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively walks the FILES array restructuring the data
|
||||
* into something sane and useable.
|
||||
*
|
||||
* @param string $path The dot separated path to insert $data into.
|
||||
* @param array $data The data to traverse/insert.
|
||||
* @param string $field The terminal field name, which is the top level key in $_FILES.
|
||||
* @return void
|
||||
*/
|
||||
protected function _processFileData($path, $data, $field) {
|
||||
foreach ($data as $key => $fields) {
|
||||
$newPath = $key;
|
||||
if (!empty($path)) {
|
||||
$newPath = $path . '.' . $key;
|
||||
}
|
||||
if (is_array($fields)) {
|
||||
$this->_processFileData($newPath, $fields, $field);
|
||||
} else {
|
||||
$newPath .= '.' . $field;
|
||||
$this->data = Set::insert($this->data, $newPath, $fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue