Skip to content

Instantly share code, notes, and snippets.

@arifmahmudrana
Created September 9, 2013 10:34
Show Gist options
  • Save arifmahmudrana/6493952 to your computer and use it in GitHub Desktop.
Save arifmahmudrana/6493952 to your computer and use it in GitHub Desktop.
Create a file on the fly using php output buffering. Sometime we need to create file on the fly this serves the purpose.
<?php
/*
* @source http://stackoverflow.com/questions/15769732/write-to-php-output-buffer-and-then-download-csv-from-buffer
*/
$basic_info = fopen("php://output", 'w'); //Open output buffer to write
$content = file_get_contents(__FILE__); //Read the current file
fwrite($basic_info, $content); //Write to output buffer
fclose($basic_info); // Close the context
header("Content-disposition: attachment; filename=index.php");
header("Content-Type: text/plain");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment