title: Slim 3 Framework how to download file
body: <p>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.</p>
  
  <p>Any help would be appreciated.
  Based on the documentation here : <a href="http://www.slimframework.com/docs/objects/response.html" rel="noreferrer">http://www.slimframework.com/docs/objects/response.html</a>
  I've added the package from here :
  <a href="https://github.com/guzzle/psr7" rel="noreferrer">https://github.com/guzzle/psr7</a></p>
  
  <p>So my code at this point looks like :</p>
  
  <pre><code>$app-&gt;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-&gt;withHeader('Content-type', 'application/octet-stream')
          -&gt;withHeader('Content-Description', 'File Transfer')
          -&gt;withHeader('Content-Disposition', 'attachment; filename=' . basename($fileName))
          -&gt;withHeader('Content-Transfer-Encoding', 'binary')
          -&gt;withHeader('Expires', '0')
          -&gt;withHeader('Cache-Control', 'must-revalidate')
          -&gt;withHeader('Pragma', 'public')
          -&gt;withHeader('Content-Length', filesize($fileName))
          -&gt;withBody($newStream);
  return($newResponse);
  });
  </code></pre>