Trouble auto-submitting a form with CURL

Hi,

I want to use PHP to auto-submit a form with a file input. Here is
the form's source:

<html>
<head></head>
<body>
<form enctype="multipart/form-data" name="f" method="post"
action="updateprices.php">
Price File <input type="file" name="pricefile" id="pricefile" /
><br>
<input type="submit" value="Submit" />
</form>
</body>
</html>

but when I attempt this code, I don't get my desired results. Here's
the code:

$postData = array();

$url = "http://mydomain.php/updateprices.php";

//simulates <input type="file" name="pricefile">
$postData[ 'pricefile' ] = "/tmp/test.csv";
$postData[ 'submit' ] = "Submit";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );

//seems no need to tell it enctype='multipart/data' it already knows
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );

$response = curl_exec( $ch );

print $response;


and here's the result:

Notice: Undefined index: pricefile in /usr/local/apache2/htdocs/
super_admin_rs/updateprices.php on line 4


Any ideas where I'm going wrong?

Thanks, - Dave
laredotornado [ Fr, 04 April 2008 01:05 ] [ ID #1935642 ]

Re: Trouble auto-submitting a form with CURL

laredotornado wrote:
> Hi,
>
> I want to use PHP to auto-submit a form with a file input. Here is
> the form's source:
>
> <html>
> <head></head>
> <body>
> <form enctype="multipart/form-data" name="f" method="post"
> action="updateprices.php">
> Price File <input type="file" name="pricefile" id="pricefile" /
>> <br>
> <input type="submit" value="Submit" />
> </form>
> </body>
> </html>
>
> but when I attempt this code, I don't get my desired results. Here's
> the code:
>
> $postData = array();
>
> $url = "http://mydomain.php/updateprices.php";
>
> //simulates <input type="file" name="pricefile">
> $postData[ 'pricefile' ] = "/tmp/test.csv";
> $postData[ 'submit' ] = "Submit";
>
> $ch = curl_init();
>
> curl_setopt($ch, CURLOPT_URL, $url );
> curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
> curl_setopt($ch, CURLOPT_POST, 1 );
>
> //seems no need to tell it enctype='multipart/data' it already knows
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
>
> $response = curl_exec( $ch );
>
> print $response;
>
>
> and here's the result:
>
> Notice: Undefined index: pricefile in /usr/local/apache2/htdocs/
> super_admin_rs/updateprices.php on line 4
>
>
> Any ideas where I'm going wrong?
>
> Thanks, - Dave
>

Your post data should look like:

'pricefile=/tmp/test.csv&submit=Submit'

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Fr, 04 April 2008 04:41 ] [ ID #1935643 ]

Re: Trouble auto-submitting a form with CURL

On Apr 3, 9:41=A0pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> laredotornado wrote:
> > Hi,
>
> > I want to use PHP to auto-submit a form with a file input. =A0Here is
> > the form's source:
>
> > <html>
> > <head></head>
> > <body>
> > <form enctype=3D"multipart/form-data" name=3D"f" method=3D"post"
> > action=3D"updateprices.php">
> > =A0 =A0Price File <input type=3D"file" name=3D"pricefile" id=3D"pricefil=
e" /
> >> <br>
> > =A0 =A0<input type=3D"submit" value=3D"Submit" />
> > </form>
> > </body>
> > </html>
>
> > but when I attempt this code, I don't get my desired results. =A0Here's
> > the code:
>
> > $postData =3D array();
>
> > $url =3D "http://mydomain.php/updateprices.php";
>
> > //simulates <input type=3D"file" name=3D"pricefile">
> > $postData[ 'pricefile' ] =3D "/tmp/test.csv";
> > $postData[ 'submit' ] =3D "Submit";
>
> > $ch =3D curl_init();
>
> > curl_setopt($ch, CURLOPT_URL, $url );
> > curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
> > curl_setopt($ch, CURLOPT_POST, 1 );
>
> > //seems no need to tell it enctype=3D'multipart/data' it already knows
> > curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
>
> > $response =3D curl_exec( $ch );
>
> > print $response;
>
> > and here's the result:
>
> > Notice: Undefined index: pricefile in /usr/local/apache2/htdocs/
> > super_admin_rs/updateprices.php on line 4
>
> > Any ideas where I'm going wrong?
>
> > Thanks, - Dave
>
> Your post data should look like:
>
> 'pricefile=3D/tmp/test.csv&submit=3DSubmit'
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D- Hide quoted text -=

>
> - Show quoted text -

Thanks. But if I had this in my post data, "pricefile=3D/tmp/test.csv",
aren't I passing the string "/tmp/test.csv" instead of the file
contents? What I would like to do is pass the file contents.

- Dave
laredotornado [ Fr, 04 April 2008 17:14 ] [ ID #1935649 ]

Re: Trouble auto-submitting a form with CURL

laredotornado wrote:
> On Apr 3, 9:41 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
>> laredotornado wrote:
>>> Hi,
>>> I want to use PHP to auto-submit a form with a file input. Here is
>>> the form's source:
>>> <html>
>>> <head></head>
>>> <body>
>>> <form enctype="multipart/form-data" name="f" method="post"
>>> action="updateprices.php">
>>> Price File <input type="file" name="pricefile" id="pricefile" /
>>>> <br>
>>> <input type="submit" value="Submit" />
>>> </form>
>>> </body>
>>> </html>
>>> but when I attempt this code, I don't get my desired results. Here's
>>> the code:
>>> $postData = array();
>>> $url = "http://mydomain.php/updateprices.php";
>>> //simulates <input type="file" name="pricefile">
>>> $postData[ 'pricefile' ] = "/tmp/test.csv";
>>> $postData[ 'submit' ] = "Submit";
>>> $ch = curl_init();
>>> curl_setopt($ch, CURLOPT_URL, $url );
>>> curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
>>> curl_setopt($ch, CURLOPT_POST, 1 );
>>> //seems no need to tell it enctype='multipart/data' it already knows
>>> curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
>>> $response = curl_exec( $ch );
>>> print $response;
>>> and here's the result:
>>> Notice: Undefined index: pricefile in /usr/local/apache2/htdocs/
>>> super_admin_rs/updateprices.php on line 4
>>> Any ideas where I'm going wrong?
>>> Thanks, - Dave
>> Your post data should look like:
>>
>> 'pricefile=/tmp/test.csv&submit=Submit'
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck... [at] attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks. But if I had this in my post data, "pricefile=/tmp/test.csv",
> aren't I passing the string "/tmp/test.csv" instead of the file
> contents? What I would like to do is pass the file contents.
>
> - Dave
>

Ah, I misunderstood what you were trying to do.

To upload a file, you need to prefix the filename with ' [at] '.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Fr, 04 April 2008 20:11 ] [ ID #1935650 ]
PHP » alt.php » Trouble auto-submitting a form with CURL

Vorheriges Thema: CMS tutorial?
Nächstes Thema: File Removal after Database Comparison