cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: libcurl, PHP, HTML forms, and an array of values

From: Shanshui Liu <me_at_lx.sg>
Date: Sat, 4 Sep 2010 04:58:37 +0800

Instead of

$posts=array('photo'=>"@bp10-02-01.jpeg",
    'img_gallery'=>'168649mojave1.jpg');

Try

$posts=array('photo[0]'=>"@bp10-02-01.jpeg",
    'img_gallery[0]'=>'168649mojave1.jpg');

More info
http://sg.php.net/manual/en/function.curl-setopt.php#62274

With regards,
Liu Shan Shui
http://lx.sg/
"Life would be much easier if I had the source code." - Anonymous

On Fri, Sep 3, 2010 at 6:25 PM, Thomas Tremain <thomas_at_tremaininc.com>wrote:

> I am trying to use cURL to post to a form, that uses an array of values,
> like:
>
> <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
> <input type="file" name="photo[]">
> <input type="file" name="photo[]">
> <input type="file" name="photo[]">
>
> or:
> <SELECT name="img_gallery[]" SIZE=3 MULTIPLE>
> <OPTION VALUE="16869.jpg"> - 16869.jpg
> <OPTION VALUE="16864.jpg"> - 16864.jpg
> </SELECT>
>
> All other POSTvars seem to work fine.
>
>
>
>
>
>
>
>
>
> $posts=array('photo'=>"@bp10-02-01.jpeg",
> 'img_gallery'=>'168649mojave1.jpg');
>
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL,$URL);
> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
> curl_setopt($ch, CURLOPT_USERAGENT, $agent);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS,$posts);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> curl_setopt($ch, CURLOPT_REFERER, $reffer);
> curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
> curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
> $result = curl_exec ($ch);
> curl_close ($ch);
> echo '----------------------<br>';
> echo("Results: <br>".$result);
>
>
>
> The files never get uploaded, because they are supposed to be in an array.
> Yet putting them in an array doesn't seem to help.
>
>
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2010-09-03