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

curl-and-php

Re: curl Upload: command line OK - libcurl/PHP problem!

From: Harry Fearnley <Harry.Fearnley_at_eng.ox.ac.uk>
Date: Fri, 02 Apr 2004 17:08:41 +0100

Daniel Stenberg wrote:

>>>In curl lingo, we don't speak of "upload" when we do a POST. A POST is
>>>just a POST. Thus, you should not set the upload option. In your case, you
>>>do a multipart formpost. (The differentiation may not matter, but the
>>>PHP/CURL module has opted for a different approach to offer multipart
>>>support so PHP programmers can't compare with other languages when it
>>>comes to this.)
>>
>>... multipart? -- see below.
>
>
>>>>$result = curl_setopt($ch, CURLOPT_POSTFIELDS,
>>>>"file=test.PDF&submit=Send%20Now");
>>>
>>>While this is POST data, it is not multipart data like you provided with
>>>the command line tools.
>>
>>I do not see how to get the effect of the command line that worked! :-).
>>
>>What do I need to do here to specify multipart data?
>
>
> Now you're reaching that part I was talking about that is offered very
> differently in PHP than "regular" libcurl.
>
> I believe you pass on a hash array to the CURLOPT_POSTFIELDS that is properly
> crafted.

I used to believe that there was nothing "magical" about hash
arrays here, and that whatever was passed as a hash array could
alternatively be passed as text ...

My understanding was that these two methods were equivalent:

A) curl_setopt($ch, CURLOPT_POSTFIELDS, "a=A&b=B");

B) $pf = array ('a' => 'A', 'b' => 'B')'
    curl_setopt($ch, CURLOPT_POSTFIELDS, $pf)

With my problem, (B) gave me "better" results than (A) -- better
only in that more of the automatically generated commands to the
HTTP server were correct -- however still does not work :-)

> We have one example on the curl site that shows a file being posted this way:
>
> http://curl.haxx.se/libcurl/php/examples/?ex=multipartpost.php
>
> If you end up producing a better example code, I'm interested!

I will try (a modification) of this code, and report my results,
though I cannot pretend to understand how it might work for a file
upload to a server other than the one that I am running the PHP
script on ... :-)

Harry

+-+-+-+-+.+-+-+-+-+.+-+-+-+-+.+-+-+-+-+.+-+-+-+-+.+-+-+-+-+.+-+-+-+-+.+-+-+-+-+-
http://www.eng.ox.ac.uk/people/Harry.Fearnley
Dept Engineering Science, Parks Rd, Oxford, OX1 3PJ, UK
Tel: +44 (0)1865 273928 -- Fax: +44 (0)1865 273010
Received on 2004-04-02