Download file from Slim Framework 2.4 Download file from Slim Framework 2.4 json json

Download file from Slim Framework 2.4


Problem solved. Turned out to be a included php class with whitespace in it. This messed up the headers i guess.

Solved by creating a new, empty project and include step by step until the bad class showed.

Working solution for setting headers inside a Slim function;

<?phprequire 'vendor/autoload.php';$app = new \Slim\Slim();$app->get('/foo', function () use ($app) {    $app->response->headers->set('Content-Type', "application/pdf");    $app->response->setBody("foo");});$app->run();?>

Updated: This is the headers I use to let a user download a PDF:

$app->response->headers->set('Content-Type', $f->type);$app->response->headers->set('Pragma', "public");$app->response->headers->set('Content-disposition:', 'attachment; filename=' . $f->name);$app->response->headers->set('Content-Transfer-Encoding', 'binary');$app->response->headers->set('Content-Length', $f->size);$app->response->setBody($f->data);