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

curl-and-php

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

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Fri, 2 Apr 2004 13:36:50 +0200 (CEST)

On Fri, 2 Apr 2004, Harry Fearnley wrote:

> It seems that to do an Upload I have to set the CURLOPT_UPLOAD option, but
> that doing this automatically sets the CURLOPT_PUT option, and I then cannot
> either unset it or set (again) the CURLOPT_POST option. The URL does not
> accept a "PUT" ...

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.)

> $result = curl_setopt($ch, CURLOPT_POST, 1);

This is what you want.

> #$result = curl_setopt($ch, CURLOPT_PUT, 1); # Doing a PUT -- needs
> the 2 lines below

This is not what you want.

> #$result = curl_setopt($ch, CURLOPT_GET, 1);

And this isn't either.

> $result = curl_setopt($ch, CURLOPT_INFILE, $handle );

You want to use the CURLOPT_POSTFIELDS instead.

> $result = curl_setopt($ch, CURLOPT_INFILESIZE, filesize( $filename ) );
> # If we do not specify the CURLOPT_INFILESIZE then there will probably
> be a delay after reading in file, waiting for a timeout ...

And you don't want this.

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

-- 
     Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
      Dedicated custom curl help for hire: http://haxx.se/curl.html
Received on 2004-04-02