PHP tmpfile() Function
❮ PHP Filesystem ReferenceExample
Create a temporary file with a unique name in read-write (w+) mode:
<?php
$temp = tmpfile();
fwrite($temp, "Testing, testing.");
//Rewind to the start of file
rewind($temp);
//Read 1k from file
echo fread($temp,1024);
//This removes the file
fclose($temp);
?>
The output of the code above will be:
Testing, testing.
Definition and Usage
The tmpfile() function creates a temporary file with a unique name in read-write (w+) mode.
Note: The file is automatically removed when closed, with fclose() or when the script ends.
Tip: See also the tempnam() function.
Syntax
tmpfile()
Technical Details
Return Value: | A file handle (similar to the one returned by fopen() for the new file), FALSE on failure |
---|---|
PHP Version: | 4.0+ |
❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.