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

curl-and-php

Re: similar question - posting a file with curl

From: <fabian.grzeszeyk_at_alti.lu>
Date: Mon, 24 Jun 2002 09:10:54 +0200

Thanks for help, now it's work fine.

                                                                                                                                                   
                      Daniel Stenberg
                      <daniel_at_haxx.se> To: Adam Schwartz <get_adam_at_yahoo.com>
                      Sent by: cc: curl and php list <curl-and-php_at_lists.sourceforge.net>
                      curl-and-php-admin_at_lists.sour Subject: Re: similar question - posting a file with curl
                      ceforge.net
                                                                                                                                                   
                                                                                                                                                   
                      24/06/2002 08:46
                                                                                                                                                   
                                                                                                                                                   

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/
-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
Received on 2002-06-24