BaiduUtils::buildHttpMultipartBody PHP Method

buildHttpMultipartBody() private static method

Build the multipart body for file uploaded request.
private static buildHttpMultipartBody ( array $params ) : string
$params array Parameters for the request
return string
    private static function buildHttpMultipartBody($params)
    {
        $body = '';
        $pairs = array();
        self::$boundary = $boundary = md5('BAIDU-PHP-SDK-V2' . microtime(true));
        foreach ($params as $key => $value) {
            if ($value[0] == '@') {
                $url = ltrim($value, '@');
                $content = file_get_contents($url);
                $array = explode('?', basename($url));
                $filename = $array[0];
                $body .= '--' . $boundary . "\r\n";
                $body .= 'Content-Disposition: form-data; name="' . $key . '"; filename="' . $filename . '"' . "\r\n";
                $body .= 'Content-Type: ' . self::detectMimeType($url) . "\r\n\r\n";
                $body .= $content . "\r\n";
            } else {
                $body .= '--' . $boundary . "\r\n";
                $body .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
                $body .= $value . "\r\n";
            }
        }
        $body .= '--' . $boundary . '--';
        return $body;
    }