curl-and-php
Re: Failed mixed post string and file upload
Date: Thu, 30 Oct 2003 09:03:42 +0100 (CET)
On Thu, 30 Oct 2003, Tilman Otto wrote:
> I tried to convert this simple HTML-form in cURL-code:
Let me first start with stating this:
This is indeed possible to do using curl. It is possible to do using the plain
libcurl interface, and it is even possible to do with the curl command line
tool. I am however not sure if this is possible to do using the PHP/CURL
interface, but then again I'm not an expert on those parts.
> <form action="http://www.externaldomain.com/importexport.php"
> method="post" enctype="multipart/form-data">
So this is a multipart formpost.
> curl_setopt($ch, CURLOPT_POSTFIELDS,$formvars);
> //segment 1 end
>
> //segment 2 begin
> curl_setopt($ch, CURLOPT_INFILE,$fp);
> curl_setopt($ch, CURLOPT_FILE,"import_file"); // With or without this
> option, the script doesn't work
This doesn't look right. When you POST with curl, you *only* POST. Adding this
file here doesn't make any difference, as that won't be used when you POST.
> I also tried this possibility in vain:
> $formvars["import_file"] = "@tool.xls"; instead of segment 2
> (CURLOPT_INFILE etc.).
That looks like the correct way.
> The post data as a string wasn't successful, too:
> $formvars = "user=anyuser&passwd=anypasswd&delall=1&action=import";
That is not the right way. You want a multipart formpost, and such a post
doesn't look like that.
> The submit variable with the value "import data" is not necessary for the
> cURL-script.
Try the command line tool and its -F option.
-- Daniel Stenberg -- curl: been grokking URLs since 1998 ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/Received on 2003-10-30