A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.yiiframework.com/doc/api/2.0/yii-web-multipartformdataparser below:

MultipartFormDataParser, yii\web\MultipartFormDataParser | API Documentation for Yii 2.0

Parses a HTTP request body.

                public function parse($rawBody, $contentType)
{
    if (!$this->force) {
        if (!empty($_POST) || !empty($_FILES)) {
            
            return $_POST;
        }
    } else {
        $_FILES = [];
    }
    if (empty($rawBody)) {
        return [];
    }
    if (!preg_match('/boundary="?(.*)"?$/is', $contentType, $matches)) {
        return [];
    }
    $boundary = trim($matches[1], '"');
    $bodyParts = preg_split('/\\R?-+' . preg_quote($boundary, '/') . '/s', $rawBody);
    array_pop($bodyParts); 
    $bodyParams = [];
    $filesCount = 0;
    foreach ($bodyParts as $bodyPart) {
        if (empty($bodyPart)) {
            continue;
        }
        list($headers, $value) = preg_split('/\\R\\R/', $bodyPart, 2);
        $headers = $this->parseHeaders($headers);
        if (!isset($headers['content-disposition']['name'])) {
            continue;
        }
        if (isset($headers['content-disposition']['filename'])) {
            
            if ($filesCount >= $this->getUploadFileMaxCount()) {
                continue;
            }
            $fileInfo = [
                'name' => $headers['content-disposition']['filename'],
                'type' => ArrayHelper::getValue($headers, 'content-type', 'application/octet-stream'),
                'size' => StringHelper::byteLength($value),
                'error' => UPLOAD_ERR_OK,
                'tmp_name' => null,
            ];
            if ($fileInfo['size'] > $this->getUploadFileMaxSize()) {
                $fileInfo['error'] = UPLOAD_ERR_INI_SIZE;
            } else {
                $tmpResource = tmpfile();
                if ($tmpResource === false) {
                    $fileInfo['error'] = UPLOAD_ERR_CANT_WRITE;
                } else {
                    $tmpResourceMetaData = stream_get_meta_data($tmpResource);
                    $tmpFileName = $tmpResourceMetaData['uri'];
                    if (empty($tmpFileName)) {
                        $fileInfo['error'] = UPLOAD_ERR_CANT_WRITE;
                        @fclose($tmpResource);
                    } else {
                        fwrite($tmpResource, $value);
                        rewind($tmpResource);
                        $fileInfo['tmp_name'] = $tmpFileName;
                        $fileInfo['tmp_resource'] = $tmpResource; 
                    }
                }
            }
            $this->addFile($_FILES, $headers['content-disposition']['name'], $fileInfo);
            $filesCount++;
        } else {
            
            $this->addValue($bodyParams, $headers['content-disposition']['name'], $value);
        }
    }
    return $bodyParams;
}

            

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4