Created
December 27, 2017 19:15
-
-
Save technoknol/5f41e3a7d157a1e85fc0af6d496b7af4 to your computer and use it in GitHub Desktop.
Php Stream - Write to temp stream and forcefully download file.
This file contains 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
<?php | |
// Set the limit to 50 MB. | |
$fiveMBs = 50 * 1024 * 1024; | |
$fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); | |
fputs($fp, $couponString); | |
// Read what we have written. | |
rewind($fp); | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename="' . ('coupons.txt') . '"'); | |
header('Expires: 0'); | |
header('Cache-Control: must-revalidate'); | |
header('Pragma: public'); | |
// header('Content-Length: ' . filesize($filepath)); | |
flush(); // Flush system output buffer | |
echo stream_get_contents($fp); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment