Skip to content

Commit

Permalink
Support requests in arrays
Browse files Browse the repository at this point in the history
Example:

* user[name] = name
* user[password] = password
* ids[] = 1
* ids[] = 2
  • Loading branch information
abetomo committed Sep 17, 2024
1 parent 1c2eb30 commit a162c64
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions no.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a162c64

Please sign in to comment.