0

I need file upload form like this

<form method="post" enctype="multipart/form-data">
<input type="file" name="f[]">
<input type="file" name="f[]">
<input type="file" name="f[]">
<input type="submit">
</form>

but in Curl.

The main problem is passing array of files with the same parameter name to build request like this:

-----boundary-2439bfe7wcbc74c8d36ef21e0c70583f
Content-Disposition: form-data; name="f[]"; filename="firstImage.gif"
Content-Type: image/gif

...skipped...


-----boundary-2439bfe7wcbc74c8d36ef21e0c70583f
Content-Disposition: form-data; name="f[]"; filename="secondImage.jpg"
Content-Type: image/jpeg

...skipped...

I know about this http://www.php.net/manual/en/function.curl-setopt.php and I confused with this CURLOPT_POSTFIELDS.

I tried to pass array:

$ch = curl_init();

$data = array('name' => 'Foo', 'f[]' => array('@/fil1.png',   '@/fil2.png'));

curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

It didn't work.

zoonman
  • 1,116
  • 1
  • 12
  • 30

0 Answers0