Skip to content

Commit a39b1f9

Browse files
author
Openset
committed
Add: upload
1 parent 142ba93 commit a39b1f9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/HttpClient.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function get($uri, array $options = [])
6565
* @return bool|\Psr\Http\Message\StreamInterface
6666
* @throws \GuzzleHttp\Exception\GuzzleException
6767
*/
68-
public static function post($url, array $options = [])
68+
public static function post($url, $options = [])
6969
{
7070
$key = is_array($options) ? 'form_params' : 'body';
7171

@@ -93,6 +93,33 @@ public function json($url, $options = '{}', array $queries = [], $encodeOption =
9393
]);
9494
}
9595

96+
/**
97+
* @param $url
98+
* @param array $files
99+
* @param array $form
100+
* @param array $queries
101+
* @return bool|\Psr\Http\Message\StreamInterface
102+
* @throws \GuzzleHttp\Exception\GuzzleException
103+
*/
104+
public static function upload($url, array $files = [], array $form = [], array $queries = [])
105+
{
106+
$multipart = [];
107+
108+
foreach ($files as $name => $path) {
109+
$multipart[] = [
110+
'name' => $name,
111+
'contents' => fopen($path, 'r'),
112+
];
113+
}
114+
115+
foreach ($form as $name => $contents) {
116+
$multipart[] = compact('name', 'contents');
117+
}
118+
119+
return self::request('POST', $url, ['query' => $queries, 'multipart' => $multipart]);
120+
}
121+
122+
96123
/**
97124
* @param $method
98125
* @param array $args

0 commit comments

Comments
 (0)