|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-04-22 15:06 UTC] bart at tremby dot net
Description: ------------ With CLI curl I can run curl -F test=value -F test=value --trace-ascii trace http://localhost/test.php and in the file trace I see that it posted multipart/form-data with two fields called "test" with content "value". I need this same behaviour from PHP. But the only way at present, it seems, to add form fields to the curl handle (and have them transmit as multipart/form-data) is to use curl_setopt($ch, CURLOPT_POSTFIELDS, $data) where $data is an array of name->value pairs. Obviously I can't have two pairs in this array with the same name. I've tried array("name" => array("val1", "val2")) but that posts the string "Array" as the value for field "name". I've tried array("name[]" => array("val1", "val2")) but that posts the string "Array" as the value for field "name[]" (PHP then parses this into an array but only "val2" is in it.) I've tried array("name[]" => "val1", "name[]" => "val2") but of course that doesn't work since as soon as that array is initialized it's only got one element -- the second overwrote the first. I think allowing array("name" => array("val1", "val2")) would be the best solution. (And brackets should not be added to the end of "name" unless specified.) Patches51634-curl-multivalued-field-post.patch (last revision 2012-05-14 20:12 UTC by raphael dot droz+floss at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
You can use: array("name[0]" => "val1", "name[1]" => "val2")