Created
December 2, 2015 18:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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