]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20616 support for array of arrays in postdata
authorskodak <skodak>
Wed, 21 Oct 2009 18:24:12 +0000 (18:24 +0000)
committerskodak <skodak>
Wed, 21 Oct 2009 18:24:12 +0000 (18:24 +0000)
lib/filelib.php

index dadb5f2e03c9b677313127dfb3377f6f8191aca6..23e404161dba880731254961ba1bc9eab75de9a6 100644 (file)
@@ -865,10 +865,23 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
 
     // use POST if requested
     if (is_array($postdata)) {
+        $data = array();
         foreach ($postdata as $k=>$v) {
-            $postdata[$k] = urlencode($k).'='.urlencode($v);
+            if (is_array($v)) {
+                foreach ($v as $sk=>$sv) {
+                    if (is_array($sv)) {
+                        foreach ($sv as $ssk=>$ssv) {
+                            $data[] = urlencode($k).'['.urlencode($sk).']['.urlencode($ssk).']='.urlencode($ssv);
+                        }
+                    } else {
+                        $data[] = urlencode($k).'['.urlencode($sk).']='.urlencode($sv);
+                    }
+                }
+            }  else {
+                $data[] = urlencode($k).'='.urlencode($v);
+            }
         }
-        $postdata = implode('&', $postdata);
+        $postdata = implode('&', $data);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
     }