cURL / Mailing Lists / curl-library / Single Mail

curl-library

problem with multipart/form-data

From: Daniel Fairchild <drxl_at_gmx.net>
Date: Mon, 20 Jun 2005 17:50:22 +0200

I've been trying to get libcurl ( libcurl/7.13.1 ) to do my exact php
(5.0.4 ) bidding for a few days now, and its not working out for me.
 From the archives I can tell that others have had the same problem:
http://curl.haxx.se/mail/lib-2003-09/0115.html

My problem is that the server I'm trying to pass multipart/form-data
checks that everything is exactly like it would be coming from a
browser. The problem is with the <input type=file> part of the http
request. Allow me to illustrate with the following html:

<form action="http://someserver.se/input.php" method="POST" name="form"
ENCTYPE="MULTIPART/FORM-DATA">
<input type="file" name="FILE1" value="null">
<input type="text" name="bogus" value="null">
<input type="submit" value="submit" name="Flyx">
</form>

Would result in the following HTTP request from a regular browser (IE 6
in this case), if we just press "submit" button without adding anything:

POST /input.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer: http://indrx.net/demo/tmp.html
Accept-Language: da
Content-Type: multipart/form-data;
boundary=---------------------------7d5f2020041a
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 1.1.4322)
Host: indrx.net
Content-Length: 389
Proxy-Connection: Keep-Alive
Pragma: no-cache

-----------------------------7d5f2020041a
Content-Disposition: form-data; name="FILE1"; filename=""
Content-Type: application/octet-stream

-----------------------------7d5f2020041a
Content-Disposition: form-data; name="bogus"

null
-----------------------------7d5f2020041a
Content-Disposition: form-data; name="Flyx"

submit
-----------------------------7d5f2020041a--

Notice that even though no data was submitted to the input file field,
there's still something about the file input in the http request. Please
note that I have no problems when actually supplying a file with
libcurl, ($post_data[FILE1] = "@pathtofile";) to the form on the server
in question. An actual files entry in the HTTP request would look
something like this btw:

Content-Disposition: form-data; name="FILE1"; filename="<path to file>"
Content-Type: text/plain

<file content>

(if using a text type file)

Maybe the functionality I'm suggesting is already present in cURL and it
just boils down to me spending 3 days looking in all the wrong places,
but I'd like to suggest the following to ensure better "likeness" to the
way real web browsers submit multipart/form-data:

When I'm setting up my post data array (to be submitted to libcurl with
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );) I'd like to be able
to add the result of empty html file forms to the http request.

I'm thinking that maybe an entry like this:
$post_data[FILE1] = "@";

should result in a HTTP request entry like this:

Content-Disposition: form-data; name="FILE1"; filename=""
Content-Type: application/octet-stream

Would that be easy enough for anyone already familiar with the code to
implement, or should I rather look into doing it myself?

Best regards Daniel Fairchild
Received on 2005-06-20