Skip to content

Instantly share code, notes, and snippets.

@phpdave
Created November 1, 2016 13:24
Show Gist options
  • Save phpdave/e25d4161253fa4f4107d58edaf0d4c4b to your computer and use it in GitHub Desktop.
Save phpdave/e25d4161253fa4f4107d58edaf0d4c4b to your computer and use it in GitHub Desktop.
Creating a temporary file in PHP
<?
$temp = tempnam(sys_get_temp_dir(), 'Prefix');
//or
$temp = tmpfile();
fwrite($temp, "Hello There!");
fseek($temp, 0);
// or could do rewind($temp)
echo fread($temp, 1024);
fclose($temp); // this removes the file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment