Created
December 11, 2017 07:39
-
-
Save aonurdemir/bb69216c27bb3589cc6de0de9b3cbf91 to your computer and use it in GitHub Desktop.
download file php
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
$fp = fopen("file.csv", 'rb'); | |
$stream = new \Slim\Http\Stream($fp); // create a stream instance for the response body | |
return $res->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="file.csv"') | |
->withHeader('Expires', '0') | |
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') | |
->withHeader('Pragma', 'public') | |
->withBody($stream); // all stream contents will be sent to the response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment