curl-and-php
Re: Hi + Multipart/Post question
Date: Thu, 3 Nov 2005 12:41:22 +0100 (CET)
On Thu, 3 Nov 2005, Simon Yorkston wrote:
> curl_setopt($ch, CURLOPT_POSTFIELDS,
> "category[1][]=orange&category[1][]=blue&category[1][]=green");
This makes a plain normal post and not a multipart one.
> But I can't include the file in that string. I tried with &file=@file, and
> @file=file_get_contents($uploadedFile); - neither of which work
>
> Alternatively, I can try
> $this->post['file'] = @$filename;
> $this->post['category[1][]'] = 'red';
> $this->post['category[1][]'] = 'blue';
> $this->post['category[1][]'] = 'yellow';
> curl_setopt($ch, CURLOPT_POSTFIELDS, $this->post);
>
> Which will upload the file, and set category to 'yellow' - but obviously not
> all three.
The PHP/CURL multipart formpost API is rather... eh, silly, if you ask me and
is very limited. This is just one of its drawbacks: you cannot send several
parts using the same name.
> $this->post['file'] = @$filename;
> curl_setopt($ch, CURLOPT_POSTFIELDS,
> "category[1][]=orange&category[1][]=blue&category[1][]=green");
> curl_setopt($ch, CURLOPT_POSTFIELDS, $this->post);
You can only set one CURLOPT_POSTFIELDS.
> Anyone have any ideas?
Yes, use the curl command line tool (from your PHP script). It can do this
just fine, using the -F option.
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.html _______________________________________________ http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-phpReceived on 2005-11-03