curl上传多文件示例
$request = curl_init('http://www.example.com/upload.php');
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($request, CURLOPT_POSTFIELDS, [
'blob[0]' => new CURLFile(realpath('first-file.jpg'), 'image/jpeg'),
'blob[1]' => new CURLFile(realpath('second-file.txt'), 'text/plain'),
'blob[2]' => new CURLFile(realpath('third-file.exe'), 'application/octet-stream'),
]);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);
var_dump(curl_getinfo($request));
curl_close($request);
GuzzleHttp上传多文件示例
$client = new \GuzzleHttp\Client();
$data =
$response = $client->request(
'POST',
'http://www.example.com/upload.php',
[
'multipart' => [ //设置
[
'name' => 'apiKey', // name: (必须,字符串) 映射到表单字段的名称。
'contents' => $apiKey, //contents: (必须,混合) 提供一个字符串,可以是 fopen 返回的资源、或者一个
],
[
'name' => 'sync_id',
'contents' => '000000',
],
[
'name' => 'typeId',
'contents' => '4',
],
[
'name' => 'blob[0]',
'contents' => fopen('D:/jljybg/180823_180823.jpg', 'r'),
],
[
'name' => 'blob[1]',
'contents' => fopen('D:/jljybg/0000200896_1412028.jpg', 'r'),
]
]
]
);