Skip to content

Commit

Permalink
Update Http.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanson authored Oct 12, 2019
1 parent 96607b6 commit 5e978d5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,30 @@ public function upload($url, array $queries = [], array $files = [], array $form
}

foreach ($form as $name => $contents) {
$multipart[] = compact('name', 'contents');
$multipart = array_merge($multipart, $this->normalizeMultipartField($name, $contents));
}

return $this->request('POST', $url, ['query' => $queries, 'multipart' => $multipart]);
}

/**
* @param string $name
* @param mixed $contents
*
* @return array
*/
public function normalizeMultipartField(string $name, $contents) {
$field = [];
if (!is_array($contents)) {
return [compact('name', 'contents')];
} else {
foreach ($contents as $key => $value) {
$key = sprintf('%s[%s]', $name, $key);
$field = array_merge($field, is_array($value) ? $this->normalizeMultipartField($key, $value) : [['name' => $key, 'contents' => $value]]);
}
}
return $field;
}

private function fileToMultipart($file)
{
Expand Down

0 comments on commit 5e978d5

Please sign in to comment.