From 161c34d9049585dc6ded4bb2c7b7d608f91db466 Mon Sep 17 00:00:00 2001 From: Bernhard Riegler Date: Fri, 27 Aug 2021 14:21:52 +0200 Subject: [PATCH] SUP-11984 check for empty files when using form generator and posting a form without filling all file inputs, we need to check wether the file is existend or fopen will throw errors --- src/MeshClient.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/MeshClient.php b/src/MeshClient.php index 223b27e..2c69db7 100644 --- a/src/MeshClient.php +++ b/src/MeshClient.php @@ -170,13 +170,16 @@ protected function setMultipart(RequestInterface $request) } foreach ($_FILES as $key => $value) { - $tmp = array(); - $tmp['name'] = $key; - $tmp['filename'] = $value['name']; - $tmp['headers']['Content-Type'] = $value['type']; - $tmp['headers']['Content-Length'] = $value['size']; - $tmp['contents'] = fopen($value['tmp_name'], 'r'); - array_push($elements, $tmp); + // only add file part if a file was provided in the request + if (!empty($value['value'])) { + $tmp = array(); + $tmp['name'] = $key; + $tmp['filename'] = $value['name']; + $tmp['headers']['Content-Type'] = $value['type']; + $tmp['headers']['Content-Length'] = $value['size']; + $tmp['contents'] = fopen($value['tmp_name'], 'r'); + array_push($elements, $tmp); + } } $body = new MultipartStream($elements); $request = $request->withBody($body)