From 6096db943fee0335f4f4152f75f60170e5229746 Mon Sep 17 00:00:00 2001 From: toxbyte Date: Sun, 14 Nov 2021 18:51:29 +0200 Subject: [PATCH] Submit form files by contents --- lib/Browser.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Browser.php b/lib/Browser.php index 84785212..1efa00f9 100644 --- a/lib/Browser.php +++ b/lib/Browser.php @@ -106,14 +106,18 @@ public function submitForm(string $url, array $fields, string $method = 'POST', $files = ''; $boundary = uniqid('', true); foreach ($fields as $name => $field) { - if (!isset($field['path'])) { - $body[$name] = $field; - } else { + $fileContent = false; + if (isset($field['path'])) { // This is a file $fileContent = file_get_contents($field['path']); - if (false !== $fileContent) { - $files .= $this->prepareMultipart($name, $fileContent, $boundary, $field); - } + } elseif (isset($field['contents'])) { + // This is a file content + $fileContent = $field['contents']; + } else { + $body[$name] = $field; + } + if (false !== $fileContent) { + $files .= $this->prepareMultipart($name, $fileContent, $boundary, $field); } }