Skip to content
Permalink
Browse files

Dispatcher::parseParams() now works with file uploads that are not in…

…dexed by model. Fixes #9
  • Loading branch information...
jperras committed Aug 13, 2009
1 parent 1a86de5 commit adc198805f96e6ac41ad1017f855973be0502aab
Showing with 38 additions and 6 deletions.
  1. +12 −6 cake/dispatcher.php
  2. +26 −0 cake/tests/cases/dispatcher.test.php
@@ -303,22 +303,28 @@ function parseParams($fromUrl) {
$params['url'] = $url;
}
}
foreach ($_FILES as $name => $data) {
if ($name != 'data') {
$params['form'][$name] = $data;
}
}
if (isset($_FILES['data'])) {
foreach ($_FILES['data'] as $key => $data) {
foreach ($data as $model => $fields) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$params['data'][$model][$field][$k][$key] = $v;
if (is_array($fields)) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$params['data'][$model][$field][$k][$key] = $v;
}
} else {
$params['data'][$model][$field][$key] = $value;
}
} else {
$params['data'][$model][$field][$key] = $value;
}
} else {
$params['data'][$model][$key] = $fields;
}
}
}
@@ -883,6 +883,32 @@ function testFileUploadArrayStructure() {
)
);
$this->assertEqual($result['data'], $expected);
$_FILES = array(
'data' => array(
'name' => array('birth_cert' => 'born on.txt'),
'type' => array('birth_cert' => 'application/octet-stream'),
'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
'error' => array('birth_cert' => 0),
'size' => array('birth_cert' => 123)
)
);
$Dispatcher =& new Dispatcher();
$result = $Dispatcher->parseParams('/');
$expected = array(
'birth_cert' => array(
'name' => 'born on.txt',
'type' => 'application/octet-stream',
'tmp_name' => '/private/var/tmp/phpbsUWfH',
'error' => 0,
'size' => 123
)
);
$this->assertEqual($result['data'], $expected);
}
/**
* testGetUrl method

0 comments on commit adc1988

Please sign in to comment.
You can’t perform that action at this time.