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; }