Trouble auto-submitting a form with CURL

Trouble auto-submitting a form with CURL

am 04.04.2008 01:05:20 von laredotornado

Hi,

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




action="updateprices.php">
Price File >






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
$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

Re: Trouble auto-submitting a form with CURL

am 04.04.2008 04:41:33 von Jerry Stuckle

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

> action="updateprices.php">
> Price File >>

>
>

>
>
>
> 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
> $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@attglobal.net
==================

Re: Trouble auto-submitting a form with CURL

am 04.04.2008 17:14:04 von laredotornado

On Apr 3, 9:41=A0pm, Jerry Stuckle wrote:
> laredotornado wrote:
> > Hi,
>
> > I want to use PHP to auto-submit a form with a file input. =A0Here is
> > the form's source:
>
> >
> >
> >
> >

> > action=3D"updateprices.php">
> > =A0 =A0Price File e" /
> >>

> > =A0 =A0
> >

> >
> >
>
> > 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
> > $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'
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- 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

Re: Trouble auto-submitting a form with CURL

am 04.04.2008 20:11:48 von Jerry Stuckle

laredotornado wrote:
> On Apr 3, 9:41 pm, Jerry Stuckle wrote:
>> laredotornado wrote:
>>> Hi,
>>> I want to use PHP to auto-submit a form with a file input. Here is
>>> the form's source:
>>>
>>>
>>>
>>>

>>> action="updateprices.php">
>>> Price File >>>>

>>>
>>>

>>>
>>>
>>> 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
>>> $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...@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 '@'.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================