Created
May 4, 2013 10:28
-
-
Save blar/5517078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class UploadManager { | |
| public $fields = array(); | |
| public function __construct() { | |
| $this->fields = $this->parse($_FILES); | |
| } | |
| protected function parse($fields) { | |
| $result = array(); | |
| foreach($this->uglify($fields) as $fieldName => $fieldValues) { | |
| foreach($fieldValues as $name => $values) { | |
| foreach($values as $index => $value) { | |
| $result[$fieldName][$index][$name] = $value; | |
| } | |
| } | |
| } | |
| return $result; | |
| } | |
| protected function uglify($fields) { | |
| foreach($fields as $fieldName => $fieldValues) { | |
| foreach($fieldValues as $name => $value) { | |
| if(!is_array($value)) { | |
| $fields[$fieldName][$name] = array($value); | |
| } | |
| } | |
| } | |
| return $fields; | |
| } | |
| public function getFiles($name) { | |
| if(!array_key_exists($name, $this->fields)) { | |
| return array(); | |
| } | |
| return $this->fields[$name]; | |
| } | |
| public function getFile($name) { | |
| $files = $this->getFiles($name); | |
| return array_shift($files); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment