/** * Returns the array with the $_FILES vars. * * @param \AppserverIo\Psr\HttpMessage\RequestInterface $request The request instance * * @return array The $_FILES vars */ protected function initFileGlobals(\AppserverIo\Psr\HttpMessage\RequestInterface $request) { // init query str $queryStr = ''; // iterate all files foreach ($request->getParts() as $part) { // check if filename is given, write and register it if ($part->getFilename()) { // generate temp filename $tempName = tempnam(ini_get('upload_tmp_dir'), 'php'); // write part $part->write($tempName); // register uploaded file $this->registerFileUpload($tempName); // init error state $errorState = UPLOAD_ERR_OK; } else { // set error state $errorState = UPLOAD_ERR_NO_FILE; // clear tmp file $tempName = ''; } // check if file has array info if (preg_match('/^([^\\[]+)(\\[.+)?/', $part->getName(), $matches)) { // get first part group name and array definition if exists $partGroup = $matches[1]; $partArrayDefinition = ''; if (isset($matches[2])) { $partArrayDefinition = $matches[2]; } $queryStr .= $partGroup . '[name]' . $partArrayDefinition . '=' . $part->getFilename() . '&' . $partGroup . '[type]' . $partArrayDefinition . '=' . $part->getContentType() . '&' . $partGroup . '[tmp_name]' . $partArrayDefinition . '=' . $tempName . '&' . $partGroup . '[error]' . $partArrayDefinition . '=' . $errorState . '&' . $partGroup . '[size]' . $partArrayDefinition . '=' . $part->getSize() . '&'; } } // parse query string to array parse_str($queryStr, $filesArray); // return files array finally. return $filesArray; }