I'm using curl to send data and files to a web service.
From the shell I execute something like this:
curl -X POST -i -F "file[]=@fil1.png" -F "file[]=@file2.pdf" -F "g=GROUP" -F "o=Object" -F "m=Body." http://localhost/api/email.php
and the web service receives an array named "file":
Array
(
[file] => Array
(
[name] => Array
(
[0] => file1.png
[1] => file2.pdf
)
[type] => Array
(
[0] => image/png
[1] => application/pdf
)
[tmp_name] => Array
(
[0] => /tmp/php1SFdK3
[1] => /tmp/phpPmwL8p
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 74040
[1] => 169090
)
)
)
If I call it from php with this code:
$data = [
"g" => "GROUP",
"o" => "object",
"m" => "body.",
"file[]" => $curlfile1,
"file[]" => $curlfile2,
];
$options = array(
CURLOPT_URL => 'http://localhost/api/email.php',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HEADERFUNCTION => "readHeader",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
the web service receives only the second file:
Array
(
[file] => Array
(
[name] => Array
(
[0] => file2.pdf
)
[type] => Array
(
[0] => application/pdf
)
[tmp_name] => Array
(
[0] => /tmp/phpPmwL8p
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 169090
)
)
)
It works fine if I put the keys in the file array:
$data = [
"g" => "GROUP",
"o" => "object",
"m" => "body.",
"file[0]" => $curlfile1,
"file[1]" => $curlfile2,
];
Is there a syntax so that I can avoid to put the keys of the file array, like in the shell command?