From a162c64818423de45910e92f090bb5f3732b2ead Mon Sep 17 00:00:00 2001 From: Abe Tomoaki Date: Tue, 17 Sep 2024 23:21:54 +0900 Subject: [PATCH] Support requests in arrays Example: * user[name] = name * user[password] = password * ids[] = 1 * ids[] = 2 --- no.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/no.php b/no.php index 4417084..5ddf461 100644 --- a/no.php +++ b/no.php @@ -85,18 +85,35 @@ function build_domain_regex($hostname) $regex .= $main_domain; return $regex; } - + +function build_multipart_data_fields($delimiter, $key, $value) { + $eol = "\r\n"; + if (!is_array($value)) { + return "--" . $delimiter . $eol + . 'Content-Disposition: form-data; name="' . $key . "\"".$eol.$eol + . $value . $eol; + } + + $data = ""; + foreach ($value as $k => $v) { + $data .= build_multipart_data_fields( + $delimiter, + sprintf("%s[%s]", $key, is_numeric($k) ? "" : $k), + $v + ); + + } + return $data; +} + function build_multipart_data_files($delimiter, $fields, $files) { # Inspiration from: https://gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f :) $data = ''; $eol = "\r\n"; - + foreach ($fields as $name => $content) { - $data .= "--" . $delimiter . $eol - . 'Content-Disposition: form-data; name="' . $name . "\"".$eol.$eol - . $content . $eol; + $data .= build_multipart_data_fields($delimiter, $name, $content); } - foreach ($files as $name => $content) { $data .= "--" . $delimiter . $eol . 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $name . '"' . $eol