I'm trying to download a file using the Slim 3 PHP Framework. Slim 2 was fairly straight forward, as I'm sure Slim 3 is too, but I just don't get it.
Any help would be appreciated. Based on the documentation here : http://www.slimframework.com/docs/objects/response.html I've added the package from here : https://github.com/guzzle/psr7
So my code at this point looks like :
$app->get('/worksheet/download/{filename}', function ($request, $response, $args) {
error_log("__________________________");
$fileName = $args['filename'];
error_log($fileName);
$newStream = new \GuzzleHttp\Psr7\LazyOpenStream($fileName, 'r');
$newResponse = $response->withHeader('Content-type', 'application/octet-stream')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Disposition', 'attachment; filename=' . basename($fileName))
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate')
->withHeader('Pragma', 'public')
->withHeader('Content-Length', filesize($fileName))
->withBody($newStream);
return($newResponse);
});