function upload()
{
- $count = count($this->request->FILES['files']['name']);
- for ($i = 0; $i < $count; ++$i) {
- $uploadfile = $this->dir . basename($this->request->FILES['files']['name'][$i]);
- move_uploaded_file($this->request->FILES['files']['tmp_name'][$i], $uploadfile);
+ foreach ($this->request->FILES['files'] as $file) {
+ $uploadfile = $this->dir . basename($file['name']);
+ move_uploaded_file($file['tmp_name'], $uploadfile);
}
return $this->backToIndex();
$this->GET =& $_GET;
$this->REQUEST =& $_REQUEST;
$this->COOKIE =& $_COOKIE;
- $this->FILES =& $_FILES;
+ $this->FILES = self::saneFiles($_FILES);
$this->method = $_SERVER['REQUEST_METHOD'];
$this->uri = $_SERVER['REQUEST_URI'];
$this->remote_addr = $_SERVER['REMOTE_ADDR'];
{
return array_merge_recursive($this->POST, $this->FILES);
}
+
+ public static function saneFiles($files)
+ {
+ $result = array();
+ foreach ($files as $prefix => $v) {
+ foreach ($v as $key => $array) {
+ array_walk_recursive($array, function(&$v, $i) use($key) {
+ $v = array($key => $v);
+ });
+ $result = self::deepMerge($result, array($prefix => $array));
+ }
+ }
+ return $result;
+ }
+
+ private static function deepMerge($into, $arr)
+ {
+ foreach ($arr as $key => $value) {
+ if (array_key_exists($key, $into) && is_array($into[$key]) && is_array($value)) {
+ $into[$key] = self::deepMerge($into[$key], $value);
+ } else {
+ $into[$key] = $value;
+ }
+ }
+ return $into;
+ }
}