tmpfile()
tmpfile() — Creates a temporary file.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Creates a temporary file with a unique name in read-write-binary (w+b) mode and returns a file handle.
Signature
tmpfile(): resource|false
Parameters
This function takes no parameters.
Return value
Returns a file handle, similar to the one returned by fopen(), for the new file or false on failure.
Example
A runnable snippet:
$temp = tmpfile(); fwrite($temp, "writing to tempfile"); fseek($temp, 0); echo fread($temp, 1024); fclose($temp); // this removes the file
Output:
writing to tempfile
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page tmpfile() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.