Bug #76216 [NEW]: Post not working with subarray and file
| From: | standa dot david at gmail dot com | Date: | Fri, 13 Apr 2018 07:49:11 +0000 |
| Subject: | Bug #76216 [NEW]: Post not working with subarray and file | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214722@lists.php.net to get a copy of this message | ||
From: standa dot david at gmail dot com
Operating system: Debian
PHP version: 7.2.4
Package: cURL related
Bug Type: Bug
Bug description:Post not working with subarray and file
Description:
------------
do you have any idea, how to post file with subarray form fields
Simple example: I need to have in form multiple var[] variables. So I
build post array:
$curlfile = curl_file_create($filename);
$postdata = array('file'=> $curlfile,
'var' => array('value1', 'value2')
);
curl_setopt($ch,CURLOPT_POSTFIELDS, $postdata);
Then I will make simple post request, but it is not working. When I
inspect the result with https://httpbin.org/post or
print_r($_POST)
variable on my site, it will show only
Array
(
[var] => Array
)
I need to have in post request var[]=value1&var[]=value2
Test script:
---------------
$curlfile = curl_file_create($filename);
$postdata = array('file'=> $curlfile,
'var' => array('value1', 'value2')
);
$ch = curl_init ("https://httpbin.org/post");
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
Expected result:
----------------
"form": {
"var[]": [
"value1",
"value2"
]
},
Actual result:
--------------
"form": {
"var": "Array",
},
--
Edit bug report at https://bugs.php.net/bug.php?id=76216&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76216&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76216&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76216&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76216&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76216&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76216&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76216&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76216&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76216&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76216&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76216&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76216&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76216&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76216&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76216&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76216&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76216&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76216&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76216&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76216&r=mysqlcfg