I'm building a Slim API for an update tool. The goal of the whole thing is, after some checks,to respond to the client with a Zipfile. This works just fine. But I don't not only want to send the client the requested zipfile, in addition I also want to add some information gathered from a database. This information is a string.
Right now my working code to respond with zipfile looks like this :
// up until this point several validations were successfully run, nothing special....
$zip = fopen($dir, 'r');
$response->write("$zip ");
$stream = new \Slim\Http\Stream($zip); // create a stream instance for the response body
//$stream = new \Slim\Http\Stream([$zip, $clientData]); // create a stream instance for the response body
//$response->getBody()->withStatus(200)->withBody("Hello, $name, ");
return $response->withHeader('Content-Type', 'application/force-download')
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Type', 'application/download')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('key', $uuid)
->withBody($stream); // all stream contents will be sent to the response
How do I have to modify it to (in pseudo php ) do this :
$zip = fopen($dir, 'r');
$response->write("$zip ");
$stream = new \Slim\Http\Stream($zip); // create a stream instance for the response body
$queryResult = 'Some JSON as string';
$responseArray = [$stream, $queryResult];
return $response->withbody($responseArray);
I tried the above solution but it did not work correctly. I get a 500 error, but string still shows up on the website. What am I missing here?