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

curl-and-php

Re: similar question - posting a file with curl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 24 Jun 2002 08:46:44 +0200 (MET DST)

On Sat, 22 Jun 2002, Adam Schwartz wrote:

> Here is my curl code:
>
> $ch = curl_init("");
>
> curl_setopt($ch, CURLOPT_URL,$URLtoPost);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $myData);
>
> curl_exec ($ch);
> curl_close ($ch);
>
> Now when $myData is a string that contains all the fields (except for the
> image) everything works.

Are you trying to emulate filling out a real form? If so, how does the HTML
for the entire <form> look like?

> So I though I could turn the image into a string and put that string into
> the string of fields that was already working:
>
> $myImgData=urlencode(fread(fopen($image,"r"),filesize($image)));
>
> $myData .= "image=".$myImgData;
>
> I'm not sure what happens here, but the recieving program seems to just
> ignore the image part... everything else still works.

First, you should separate 'image' from the other fields using a '&' letter.
Secondly, it looks very odd that anyone would use a "standard" form to allow
anyone to post an image to a site. I've never seen it used like this.

> Next I thought I could make an associative array instead of a string to
> send to curlopt_postfields.

I've read the PHP/CURL module source code, so I know this instead turns the
post into a multipart formpost which is a totally different way of sending
the data to the remote host. The host was most likely programmed to just
receive one kind of POST, so you cannot simple pick one you like, you need to
use the one the receiver expects.

> Finally, I have a theory that I could use curlopt_file in conjuction with
> curlopt_postfields. But I'm not sure how this works.

Nope, you won't be able to do that. It is used differently.

I'm not a PHP hacker, but I know my way around in the curl world.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
Received on 2002-06-24