PHP tmpfile()Function


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual

Definition and Usage

The tmpfile() function creates a temporary file with a unique filename in read-write (w+) mode.

Syntax

tmpfile()


Tips and Notes

Note:The temporary file will be automatically deleted after the file is closed (with fclose()) or when the script ends.

Tip:See also tempnam().


Example

<?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 above code will output:

Testing, testing.


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual Other Extensions