_raw = $files_data; if ($this->_raw ) { // check if it's multiple or single file upload if ($this->_is_multiple()) { foreach ($this->_raw['error'] as $key => $error) { if (!$this->_raw['name'][$key]) continue; $file = new File([ 'name' => $this->_raw['name'][$key], 'type' => $this->_raw['type'][$key], 'tmp_name' => $this->_raw['tmp_name'][$key], 'error' => $error, 'size' => $this->_raw['size'][$key], ], $validations); $this->files[] = $file; } // let the single "file" property be the first file (index 0) if ($this->files) $this->file = $this->files[0]; } else if ($this->_raw['name']) { $file_info = []; foreach ($this->_raw as $key => $value) { $file_info[$key] = $value; } $file = new File($file_info, $validations); $this->files[] = $file; $this->file = $this->files[0]; } } } /** * loop through each file * @param closure $callback callback function for each file */ public function each($callback) { if (is_object($obj) && ($obj instanceof \Closure)) { foreach ($this->files as $file) { $callback($file); } } } /** * check if the upload data is multiple or not * @return boolean true if multiple, otherwise false */ private function _is_multiple() { return is_array($this->_raw['name']); } } ?>