From b54c3b030878e95fd706bcc0b19ddde0f238ff88 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 17 Apr 2012 22:28:08 -0400 Subject: [PATCH] Convert FILES processing to use recursion. Fixes issues with deeply nested file data issues. Fixes #2796 --- lib/Cake/Network/CakeRequest.php | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 977261ef9..e665db301 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -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); } } }