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

curl-and-php

Re: multipart/form-data posts

From: Pete James <Pete_James_at_advanis.ca>
Date: Mon, 01 Oct 2001 08:13:40 -0600

I ended up getting it to work by using CURLOPT_POSTFIELDS. In php it
seems that POSTFIELDS does support multipart to some degree. How, you
ask?

In the three-tier system I'm using, the form posts to PHP_SELF which
resides on the web server, which then executes the curl functions to
post to the backend application server. When it calls itself, it posts
the file, and you get the temp filename on the local machine. If you
put this in POSTFIELDS as an array like so:

curl_setopt($ch, CURLOPT_POSTFIELDS, array
('newpostvarname'=>"@$prevpostvarname")

the file will be reposted, just as it was the first time. The @ symbol
seems to specify a multipart transfer.
I found this in the forum under the curl_setopt() function description
on PHP.NET.

I hope this'll help others.

Thks,
Pete

Daniel Stenberg wrote:
>
> On Fri, 28 Sep 2001, Pete James wrote:
>
> > Now I need to re-send the form to the backend page for processing. How
> > do I fake a multipart/form-data post in php?? What I've already learned:
> > CURLOPT_HTTPPOST would seem to be an answer, but it seems unsupported in
> > php;
>
> CURLOPT_HTTPPOST is indeed used for multipart/form-data posts. The hard thing
> is to setup the linked list properly, which in libcurl used to be done with
> curl_formparse() which since 7.9 is being replaced with curl_formadd(). None
> of those functions seem to exist in the PHP interface...!
>
> > using CURLOPT_POSTFIELDS with name=@filename doesn't seem to work...
> > perhaps because it's urlencoded.
>
> No, it doesn't work because it sends the data very differently.
>
> > Has nobody ever needed to do this, or am I really missing something??
>
> If nothing else, you can do this using the command line client. I mean,
> that's probably not what you want to do but can be a work-around until it
> works in PHP...
>
> --
> Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/

-- 
Pete James, Advanis
Received on 2001-10-01