0

I try download file .png use Slim 3 with this code:

$app->get('/api/download/content/image/{filename}', function($request, Slim\Http\Response $response, $args) {
$file = __DIR__ . '/uploads/content/image/'. $args['filename'];
$fh = fopen($file, 'rb');

$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body

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('Content-Disposition', 'attachment; filename="' . basename($file) . '"')
    ->withHeader('Expires', '0')
    ->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
    ->withHeader('Pragma', 'public')
    ->withBody($stream); });

But the download dialog not show. only show string

Result from Slim

Rofie Sagara
  • 289
  • 5
  • 17

0 Answers0