Post 文件数组 PHP curl

Post file array with PHP curl

我想 post 使用 PHP 和 curl 将一组文件发送到服务器。在 HTML 中,它看起来如下:

<form method="POST" type="multipart/form-data">
    <input type="text" name="fieldx" value="123"/>
    <input type="file" name="localfile[]"/>
    <input type="file" name="localfile[]"/>
</form>

CURL 也应该这样做:

$postParameters['fieldx'] = "123";
$postParameters['localfile'] = array("fulllocalfilepath1", "fulllocalfilepath2");

$request = curl_init('http://server.abc');
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
    $request,
    CURLOPT_POSTFIELDS,
    $postParameters
);  
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($request);
curl_close($request);

但是服务器在使用CURL 时收不到localfile 数组。发送文件的正确命令是什么?

此致,

得到解决方案:

$postParameters['fieldx'] = "123";
$postParameters['localfile[0]'] = new cURLFile("fulllocalfilepath1", "mime", "readable name 1");
$postParameters['localfile[1]'] = new cURLFile("fulllocalfilepath2", "mime", "readable name 2");
$request = curl_init('http://server.abc');
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
    $request,
    CURLOPT_POSTFIELDS,
    $postParameters
);  
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($request);
curl_close($request);