Skip to content

Instantly share code, notes, and snippets.

@shtrih
Created January 30, 2017 13:19
Show Gist options
  • Save shtrih/7c15621747f08f220543e55199c5b2e2 to your computer and use it in GitHub Desktop.
Save shtrih/7c15621747f08f220543e55199c5b2e2 to your computer and use it in GitHub Desktop.
<?php
function getTmp() {
// returns file handle, similar to the one returned by fopen, for the new file or false on failure.
$handle = tmpfile();
$path = stream_get_meta_data($handle)['uri'];
var_dump(fwrite($handle, 'foo')); // 3
var_dump(fread($handle, 42)); // ""
var_dump(fgets($handle)); // false
var_dump(file_get_contents($path)); // "foo"
var_dump(file_exists($path)); // true
return $path;
}
$path = getTmp();
var_dump(file_exists($path)); // false ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment