Latest web development tutorials

PHP tmpfile () function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual

Definition and Usage

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

grammar

tmpfile()


Tips and Notes

Note: Temporary files after the file is closed (using fclose ()), or when the script ends automatically deleted.

Tip: See tempnam ().


Examples

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

Testing, testing.


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual