Skip to content

Commit

Permalink
SUP-11984 check for empty files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bernhardriegler authored Aug 27, 2021
1 parent b683b6a commit 161c34d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/MeshClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 161c34d

Please sign in to comment.