Skip to content

Commit a162c64

Browse files
committed
Support requests in arrays
Example: * user[name] = name * user[password] = password * ids[] = 1 * ids[] = 2
1 parent 1c2eb30 commit a162c64

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

no.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,35 @@ function build_domain_regex($hostname)
8585
$regex .= $main_domain;
8686
return $regex;
8787
}
88-
88+
89+
function build_multipart_data_fields($delimiter, $key, $value) {
90+
$eol = "\r\n";
91+
if (!is_array($value)) {
92+
return "--" . $delimiter . $eol
93+
. 'Content-Disposition: form-data; name="' . $key . "\"".$eol.$eol
94+
. $value . $eol;
95+
}
96+
97+
$data = "";
98+
foreach ($value as $k => $v) {
99+
$data .= build_multipart_data_fields(
100+
$delimiter,
101+
sprintf("%s[%s]", $key, is_numeric($k) ? "" : $k),
102+
$v
103+
);
104+
105+
}
106+
return $data;
107+
}
108+
89109
function build_multipart_data_files($delimiter, $fields, $files) {
90110
# Inspiration from: https://gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f :)
91111
$data = '';
92112
$eol = "\r\n";
93-
113+
94114
foreach ($fields as $name => $content) {
95-
$data .= "--" . $delimiter . $eol
96-
. 'Content-Disposition: form-data; name="' . $name . "\"".$eol.$eol
97-
. $content . $eol;
115+
$data .= build_multipart_data_fields($delimiter, $name, $content);
98116
}
99-
100117
foreach ($files as $name => $content) {
101118
$data .= "--" . $delimiter . $eol
102119
. 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $name . '"' . $eol

0 commit comments

Comments
 (0)