• PHP Video Tutorials

PHP - Function tmpfile()



The tmpfile() function can create a temporary file with a unique name in the read-write (w+) mode. This function can return filehandle similar to the one returned by the fopen() function for the new file, or false on failure.

Syntax

resource tmpfile ( void )

This function can create a temporary file with a unique name in the read-write (w+) mode and return a filehandle. The file is automatically removed when it is closed (for instance, by calling fclose() function or when there are no remaining references to filehandle returned by tmpfile() function), or when the script ends.

Example

<?php
   $temp = tmpfile();
   fwrite($temp, "Tutorialspoint!!!!");
   rewind($temp);  // Rewind to start of a file
   echo fread($temp, 1024);  // Read 1k from a file
   
   fclose($temp);  // it removes the file
?>

Output

Tutorialspoint!!!!
php_function_reference.htm
Advertisements