#50060 [Bgs]: "failed creating formpost data" if post array value starts with '@'
| From: | scottmac@php.net | Date: | Tue, 03 Nov 2009 11:58:31 +0000 |
| Subject: | #50060 [Bgs]: "failed creating formpost data" if post array value starts with '@' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144203@lists.php.net to get a copy of this message | ||
ID: 50060
Updated by: scottmac@php.net
Reported By: bugs dot php dot net at sgerrand dot com
Status: Bogus
Bug Type: cURL related
Operating System: Linux (Ubuntu x86_64 2.6.31-14)
PHP Version: 5.2.11
New Comment:
-d is for the whole data, what we really have here is -F for formdata.
curl -F 'key=@value' http://www.php.net/
Previous Comments:
------------------------------------------------------------------------
[2009-11-03 10:44:13] bugs dot php dot net at sgerrand dot com
Please refer to the documentation for curl_setopt() -
http://php.net/curl_setopt
CURLOPT_POSTFIELDS The full data to post in a HTTP "POST"
operation. To post a file, prepend a filename with @ and use the full
path. This can either be passed as a urlencoded string like
'para1=val1¶2=val2&...' or as an array with the field name as key
and field data as value. If value is an array, the Content-Type header
will be set to multipart/form-data.
The case I have logged is when data to be posted using this option is
an array which happens to have a value that starts with '@', as per
the example. This edge case is being caused by the function used to
create the form data to pass to cURL.
I would note that the cURL command line client on any POSIX system can
perform this without issue - i.e.:
curl -d 'key=@value' http://www.php.net/
------------------------------------------------------------------------
[2009-11-03 10:18:06] scottmac@php.net
@ has a special meaning with cURL and takes the contents of the file.
------------------------------------------------------------------------
[2009-11-03 07:29:36] bugs dot php dot net at sgerrand dot com
Description:
------------
PHP's cURL library dies returning the error message "failed creating
formpost data" when trying to use an array that contains a value
starting with '@'.
If the array is changed to a string in URL encoded like format, the
problem does not occur.
Reproduce code:
---------------
<?php
$url = 'http://www.php.net';
$postData = array('key' => '@value');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
if (! curl_exec($ch) ) print 'cURL error: ' . curl_error($ch);
else print "cURL success";
curl_close($ch);
?>
Expected result:
----------------
cURL success
Actual result:
--------------
cURL error: failed creating formpost data
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50060&edit=1