Skip to content

Instantly share code, notes, and snippets.

@aonurdemir
Created December 11, 2017 07:39
Show Gist options
  • Save aonurdemir/bb69216c27bb3589cc6de0de9b3cbf91 to your computer and use it in GitHub Desktop.
Save aonurdemir/bb69216c27bb3589cc6de0de9b3cbf91 to your computer and use it in GitHub Desktop.
download file php
$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