Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created December 2, 2015 18:57
Show Gist options
  • Save khoand0000/210f341a67227e245763 to your computer and use it in GitHub Desktop.
Save khoand0000/210f341a67227e245763 to your computer and use it in GitHub Desktop.
make file download with slim framework ref: http://help.slimframework.com/discussions/questions/359-file-download
$app = new \Slim\Slim();
$app->get('/downloadlog', function () use($app) {
$log = 'mylogfile.log';
$res = $app->response();
$res['Content-Description'] = 'File Transfer';
$res['Content-Type'] = 'application/octet-stream';
$res['Content-Disposition'] ='attachment; filename=' . basename($log);
$res['Content-Transfer-Encoding'] = 'binary';
$res['Expires'] = '0';
$res['Cache-Control'] = 'must-revalidate';
$res['Pragma'] = 'public';
$res['Content-Length'] = filesize($log);
readfile($log);
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment