-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
curl-ext.php
53 lines (40 loc) 路 1.18 KB
/
curl-ext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
$localFiles = [
// indexed
'documents' => [
__DIR__ . '/resource/file-1.txt',
__DIR__ . '/resource/file-2.txt',
],
// associated
'images' => [
'icon' => __DIR__ . '/resource/github-icon.png',
'octocat' => __DIR__ . '/resource/github-octocat.jpg',
],
];
$uploadFiles = [];
foreach ($localFiles as $fileType => $files) {
foreach ($files as $filePostKey => $uploadFilePath) {
if (!file_exists($uploadFilePath)) {
throw new Exception('File not found: ' . $uploadFilePath);
}
$uploadFileMimeType = mime_content_type($uploadFilePath);
$keyName = sprintf('%s[%s]', $fileType, $filePostKey);
$uploadFiles[$keyName] = new CURLFile($uploadFilePath, $uploadFileMimeType, $filePostKey);
}
}
$curlHandler = curl_init();
curl_setopt_array($curlHandler, [
CURLOPT_URL => 'https://postman-echo.com/post',
CURLOPT_RETURNTRANSFER => true,
/**
* Specify POST method
*/
CURLOPT_POST => true,
/**
* Specify array of form fields
*/
CURLOPT_POSTFIELDS => $uploadFiles,
]);
$response = curl_exec($curlHandler);
curl_close($curlHandler);
echo($response);