Permalink
Browse files

Convert FILES processing to use recursion.

Fixes issues with deeply nested file data issues.
Fixes #2796
  • Loading branch information...
1 parent c15259f commit b54c3b030878e95fd706bcc0b19ddde0f238ff88 @markstory markstory committed Apr 18, 2012
Showing with 25 additions and 15 deletions.
  1. +25 −15 lib/Cake/Network/CakeRequest.php
@@ -320,21 +320,31 @@ protected function _processFiles() {
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);
}
}
}

0 comments on commit b54c3b0

Please sign in to comment.